Start New Discussion within our Software Development Community

Hi,

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"
rst.Open

If rst.BOF = False Then
Combo1.Clear
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. . .

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

http://visualbasic.freetutes.com/learn-vb6-advanced/lesson8/

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 article has been dead for over six months. Start a new discussion instead.