[prev in list] [next in list] [prev in thread] [next in thread]
List: postgresql-general
Subject: [GENERAL] It WORKS! I am exultant. Hallelujah!
From: Typing80wpm () aol ! com
Date: 2005-04-30 14:22:23
Message-ID: 11.44647e1a.2fa526df () aol ! com
[Download RAW message or body]
_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
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=US-ASCII">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR></HEAD>
<BODY id=role_body style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Arial"
bottomMargin=7 leftMargin=7 topMargin=7 rightMargin=7><FONT id=role_document
face=Arial color=#000000 size=2>
<DIV><A
href="http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-visualbasic">http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-visualbasic</A></DIV>
<DIV> </DIV>
<DIV>Thanks for the link Jeff, that was exactly what I needed, plus a little
brushing up in Visual Basic. </DIV>
<DIV> </DIV>
<DIV>Here is the code which finally worked!</DIV>
<DIV> </DIV>
<DIV>It DOES want the DSN to equal "PostgreSQL", rather than something
else.</DIV>
<DIV> </DIV>
<DIV>For some reason, certain commands DO NOT WORK, so I had to comment them
out:</DIV>
<DIV> </DIV>
<DIV>One of which is: </DIV>
<DIV> </DIV>
<DIV> 'rs.Refresh</DIV>
<DIV> </DIV>
<DIV>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</DIV>
<DIV> </DIV>
<DIV>
<DIV> 'Get the record count<BR> rs.MoveLast<BR>
rs.MoveFirst<BR> MsgBox rs.RecordCount & " Records are in the
recordset!"</DIV>
<DIV> </DIV>
<DIV> </DIV></DIV>
<DIV>===============================here is the code which works</DIV>
<DIV>Private Sub Command1_Click()<BR>Dim cn As New ADODB.Connection<BR>Dim rs As
New ADODB.Recordset</DIV>
<DIV> </DIV>
<DIV> 'Open the connection<BR> cn.Open "DSN=PostgreSQL;" &
_<BR> "UID=neil;" &
_<BR> "PWD=password;"
& _<BR>
"Database=bpsimple"<BR> 'For updateable recordsets we would typically open
a Dynamic recordset.<BR> 'Forward Only recordsets are much faster but can
only scroll forward and<BR> 'are read only. Snapshot recordsets are read
only, but scroll in both<BR> 'directions.<BR> <BR> rs.Open
"SELECT fname, lname FROM customer", cn, adOpenDynamic<BR> <BR> 'Loop
though the recordset and print the results<BR> 'We will also update the
accessed column, but this time access it through<BR> 'the Fields
collection. ISO-8601 formatted dates/times are the safest IMHO.<BR> While
Not rs.EOF<BR> Debug.Print rs!fname & ": " &
rs!lname<BR> rs.MoveNext<BR> Wend<BR> </DIV>
<DIV> </DIV>
<DIV> 'Insert a new record into the table<BR> cn.Execute "INSERT
INTO customer (fname, lname, zipcode) VALUES ('hooray', 'Some random Data ',
'123');"</DIV>
<DIV> </DIV>
<DIV> 'Refresh the recordset to get that last record...<BR>
'rs.Refresh</DIV>
<DIV> </DIV>
<DIV> 'Get the record count<BR> rs.MoveLast<BR>
rs.MoveFirst<BR> MsgBox rs.RecordCount & " Records are in the
recordset!"</DIV>
<DIV> </DIV>
<DIV> 'Cleanup<BR> If rs.State <> adStateClosed Then
rs.Close<BR> Set rs = Nothing<BR> If cn.State <> adStateClosed
Then cn.Close<BR> Set cn = Nothing</DIV>
<DIV> </DIV>
<DIV>End Sub<BR>====================end of code</DIV></FONT></BODY></HTML>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic