Click here to Skip to main content
15,886,678 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
h0w to show the contents of table in database in listbox or in grid......?
Posted
Comments
Richard MacCutchan 25-Sep-13 3:24am    
Read the records and add them to the list, or use databinding.

1 solution

What i understand is you want to show data from database to To Datagrid in vb6
If yes then you can try following code
VB
Dim con As New ADODB.Connection
Dim Rs as new adodb.recordset

if con.state = 1 then con.close
''I am using Sql Server so i am using following string.. let me know what database you are using.
    Con.Open _
            "Provider = sqloledb;" & _
            "Data Source=servername;" & _
            "Initial Catalog=DatabaseName;" & _
            "User ID=username;" & _
            "Password=password;"

If RS.State = 1 Then RS.Close
RS.Open "select field1, field2, field3 from YourTable", con, adOpenKeyset, adLockOptimistic

If RS.RecordCount > 0 Then
    Set DataGrid1.DataSource = RS
Else
    msgbox "Record Not found", vbCritical, "My DataGrid"
end if

Please let me know if you have more query.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900