I used PostgreSQL and i want to populate its fields in combo box.

Is anyone know how to make it. .

Please help me. . . it is for my project. . :icon_sad:

Here is my code:

Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sSQL As String
Dim IvAR As Integer

Set conn = New ADODB.Connection
conn.ConnectionString = connString
conn.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=PostgreSQL30;Initial Catalog=PostgreSQL"

Set rst = New ADODB.Recordset
rst.ActiveConnection = conn
rst.CursorLocation = adUseClient
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Fields = "inventory"

If rst.BOF = False Then
For IvAR = 0 To rst.Fields.Count - 1
Combo1.AddItem rst.Fields(IvAR).Name
Combo1.ItemData(Combo1.NewIndex) = IvAR
Next IvAR
If Combo1.ListCount > 0 Then
Combo1.ListIndex = 1
End If
End If

, , Is this correct or not. . if not. . please help me to correct my codes. . . :(

I hope you help me. . .

Thanks in advance. . .

7 Years
Discussion Span
Last Post by vb5prgrmr

If you need a tutorial there are nearly hundreds out there...


Now, as for your code I see that on this line...

conn.ConnectionString = connString

you do not have connString defined anywhere nor can one see what if any value connString holds and then on the next line were you do...

conn.Open "Provider=MSDASQL.1;Persist Security Info=False;Data Source=PostgreSQL30;Initial Catalog=PostgreSQL"

Well! That is your connection string!

So have a look at a tutorial or use the data form wizard with an ODBC DSN then see http://www.connectionstrings.com to change your connection string to a DSN Less connection string.

Good Luck

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.