[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>&nbsp;</DIV>
<DIV>Thanks for the link Jeff, that was exactly what I needed, plus a little 
brushing up in Visual Basic. </DIV>
<DIV>&nbsp;</DIV>
<DIV>Here is the code which finally worked!</DIV>
<DIV>&nbsp;</DIV>
<DIV>It DOES want the DSN to equal "PostgreSQL", rather than something 
else.</DIV>
<DIV>&nbsp;</DIV>
<DIV>For some reason, certain commands DO NOT WORK, so I had to comment them 
out:</DIV>
<DIV>&nbsp;</DIV>
<DIV>One of which is: </DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; 'rs.Refresh</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>
<DIV>&nbsp; 'Get the record count<BR>&nbsp; rs.MoveLast<BR>&nbsp; 
rs.MoveFirst<BR>&nbsp; MsgBox rs.RecordCount &amp; " Records are in the 
recordset!"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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>&nbsp;</DIV>
<DIV>&nbsp; 'Open the connection<BR>&nbsp; cn.Open "DSN=PostgreSQL;" &amp; 
_<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "UID=neil;" &amp; 
_<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "PWD=password;" 
&amp; _<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
"Database=bpsimple"<BR>&nbsp; 'For updateable recordsets we would typically open 
a Dynamic recordset.<BR>&nbsp; 'Forward Only recordsets are much faster but can 
only scroll forward and<BR>&nbsp; 'are read only. Snapshot recordsets are read 
only, but scroll in both<BR>&nbsp; 'directions.<BR>&nbsp; <BR>&nbsp; rs.Open 
"SELECT fname, lname FROM customer", cn, adOpenDynamic<BR>&nbsp;<BR>&nbsp; 'Loop 
though the recordset and print the results<BR>&nbsp; 'We will also update the 
accessed column, but this time access it through<BR>&nbsp; 'the Fields 
collection. ISO-8601 formatted dates/times are the safest IMHO.<BR>&nbsp; While 
Not rs.EOF<BR>&nbsp;&nbsp;&nbsp; Debug.Print rs!fname &amp; ": " &amp; 
rs!lname<BR>&nbsp;&nbsp;&nbsp; rs.MoveNext<BR>&nbsp; Wend<BR>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; 'Insert a new record into the table<BR>&nbsp; cn.Execute "INSERT 
INTO customer (fname, lname, zipcode) VALUES ('hooray', 'Some random Data ', 
'123');"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; 'Refresh the recordset to get that last record...<BR>&nbsp; 
'rs.Refresh</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; 'Get the record count<BR>&nbsp; rs.MoveLast<BR>&nbsp; 
rs.MoveFirst<BR>&nbsp; MsgBox rs.RecordCount &amp; " Records are in the 
recordset!"</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; 'Cleanup<BR>&nbsp; If rs.State &lt;&gt; adStateClosed Then 
rs.Close<BR>&nbsp; Set rs = Nothing<BR>&nbsp; If cn.State &lt;&gt; adStateClosed 
Then cn.Close<BR>&nbsp; Set cn = Nothing</DIV>
<DIV>&nbsp;</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