It WORKS! I am exultant. Hallelujah!

From: Typing80wpm(at)aol(dot)com
To: pgsql-general(at)postgresql(dot)org
Cc: pgsql-odbc(at)postgresql(dot)org
Subject: It WORKS! I am exultant. Hallelujah!
Date: 2005-04-30 14:22:23
Message-ID: 11.44647e1a.2fa526df@aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-odbc

_http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-visualbasic_
(http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-visualbasic)

Thanks for the link Jeff, that was exactly what I needed, plus a little
brushing up in Visual Basic.

Here is the code which finally worked!

It DOES want the DSN to equal "PostgreSQL", rather than something else.

For some reason, certain commands DO NOT WORK, so I had to comment them out:

One of which is:

'rs.Refresh

and, possibly, because rs.Refresh did not work, and got commented out,
therefore, the recordcount commands worked, (compiled and ran with no error), but
yielded an incorrect answer of - 1


'Get the record count
rs.MoveLast
rs.MoveFirst
MsgBox rs.RecordCount & " Records are in the recordset!"

===============================here is the code which works
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset

'Open the connection
cn.Open "DSN=PostgreSQL;" & _
"UID=neil;" & _
"PWD=password;" & _
"Database=bpsimple"
'For updateable recordsets we would typically open a Dynamic recordset.
'Forward Only recordsets are much faster but can only scroll forward and
'are read only. Snapshot recordsets are read only, but scroll in both
'directions.

rs.Open "SELECT fname, lname FROM customer", cn, adOpenDynamic

'Loop though the recordset and print the results
'We will also update the accessed column, but this time access it through
'the Fields collection. ISO-8601 formatted dates/times are the safest IMHO.
While Not rs.EOF
Debug.Print rs!fname & ": " & rs!lname
rs.MoveNext
Wend

'Insert a new record into the table
cn.Execute "INSERT INTO customer (fname, lname, zipcode) VALUES ('hooray',
'Some random Data ', '123');"

'Refresh the recordset to get that last record...
'rs.Refresh

'Get the record count
rs.MoveLast
rs.MoveFirst
MsgBox rs.RecordCount & " Records are in the recordset!"

'Cleanup
If rs.State <> adStateClosed Then rs.Close
Set rs = Nothing
If cn.State <> adStateClosed Then cn.Close
Set cn = Nothing

End Sub
====================end of code

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Eckermann 2005-04-30 17:06:22 Re: [ODBC] Adventures with P2P and Scripts in Windows
Previous Message Ian Harding 2005-04-30 14:19:39 Re: Problem while using commit..

Browse pgsql-odbc by date

  From Date Subject
Next Message Shachar Shemesh 2005-04-30 14:48:41 Re: Official ODBC announcement
Previous Message Typing80wpm 2005-04-30 13:56:27 VB questions re: Postgresql, Connect...etc