Search Postgresql Archives

It WORKS! I am exultant. Hallelujah!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 
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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux