X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E93D753A2B; Sat, 30 Apr 2005 15:22:36 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 84111-10; Sat, 30 Apr 2005 18:22:32 +0000 (GMT) Received: from imo-m14.mx.aol.com (imo-m14.mx.aol.com [64.12.138.204]) by svr1.postgresql.org (Postfix) with ESMTP id 90CF053983; Sat, 30 Apr 2005 15:22:27 -0300 (ADT) Received: from Typing80wpm@aol.com by imo-m14.mx.aol.com (mail_out_v38_r1.7.) id k.11.44647e1a (4004); Sat, 30 Apr 2005 14:22:23 -0400 (EDT) From: Typing80wpm@aol.com Message-ID: <11.44647e1a.2fa526df@aol.com> Date: Sat, 30 Apr 2005 14:22:23 EDT Subject: It WORKS! I am exultant. Hallelujah! To: pgsql-general@postgresql.org Cc: pgsql-odbc@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------------------------1114885343" X-Mailer: 9.0 SE for Windows sub 5012 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.625 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, HTML_40_50, HTML_MESSAGE, MANY_EXCLAMATIONS, NO_REAL_NAME X-Spam-Level: X-Archive-Number: 200504/1430 X-Sequence-Number: 77343 -------------------------------1114885343 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit _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 -------------------------------1114885343 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
http://gborg.postgresql.org/project/psqlodbc/genpage.php?howto-visua= lbasic
 
Thanks for the link Jeff, that was exactly what I needed, plus a little= =20 brushing up in Visual Basic.
 
Here is the code which finally worked!
 
It DOES want the DSN to equal "PostgreSQL", rather than something=20 else.
 
For some reason, certain commands DO NOT WORK, so I had to comment them= =20 out:
 
One of which is:
 
  'rs.Refresh
 
and, possibly, because rs.Refresh did not work, and got commented out,=20 therefore, the recordcount commands worked, (compiled and ran with no error)= ,=20 but yielded an incorrect answer of - 1
 
  'Get the record count
  rs.MoveLast
 =20 rs.MoveFirst
  MsgBox rs.RecordCount & " Records are in the=20 recordset!"
 
 
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3Dhere is the code which works
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim r= s As=20 New ADODB.Recordset
 
  'Open the connection
  cn.Open "DSN=3DPostgreSQL;" &= =20 _
          "UID=3Dneil;" &a= mp;=20 _
          "PWD=3Dpassword;= "=20 & _
         =20 "Database=3Dbpsimple"
  'For updateable recordsets we would typicall= y open=20 a Dynamic recordset.
  'Forward Only recordsets are much faster but=20= can=20 only scroll forward and
  'are read only. Snapshot recordsets are re= ad=20 only, but scroll in both
  'directions.
 
  rs.Open= =20 "SELECT fname, lname FROM customer", cn, adOpenDynamic
 
  '= Loop=20 though the recordset and print the results
  'We will also update th= e=20 accessed column, but this time access it through
  'the Fields=20 collection. ISO-8601 formatted dates/times are the safest IMHO.
  Wh= ile=20 Not rs.EOF
    Debug.Print rs!fname & ": " &=20 rs!lname
    rs.MoveNext
  Wend
 
 
  'Insert a new record into the table
  cn.Execute "INSERT= =20 INTO customer (fname, lname, zipcode) VALUES ('hooray', 'Some random Data ',= =20 '123');"
 
  'Refresh the recordset to get that last record...
 =20 'rs.Refresh
 
  'Get the record count
  rs.MoveLast
 =20 rs.MoveFirst
  MsgBox rs.RecordCount & " Records are in the=20 recordset!"
 
  'Cleanup
  If rs.State <> adStateClosed Then=20 rs.Close
  Set rs =3D Nothing
  If cn.State <> adState= Closed=20 Then cn.Close
  Set cn =3D Nothing
 
End Sub
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3Dend of code
-------------------------------1114885343--