From: Typing80wpm@aol.com
To: pgsql-general@postgresql.org
Cc: pgsql-odbc@postgresql.org
Subject: It WORKS! I am exultant. Hallelujah!
Date: Sat, 30 Apr 2005 14:22:23 EDT
Message-ID: <11.44647e1a.2fa526df@aol.com> (raw)
_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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: Typing80wpm@aol.com, pgsql-general@postgresql.org
Subject: Re: It WORKS! I am exultant. Hallelujah!
In-Reply-To: <11.44647e1a.2fa526df@aol.com>
References: <11.44647e1a.2fa526df@aol.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox