Hi all,

1. I want to know how to add a data grid in vb 6 form?
2. And how to fetch all records in data grid

please help

Thanks in advance for help.

Thanks for your reply i didn't want to use data tool loke adodc or data1 i want to control it progmatically please help

I am using this code to fetch all records in datagrid but it didn't work for me gives error object required please help.

Dim db As Database
Dim rs As Recordset
Dim admissionssql As String
Private Sub Form_Load()
Set db = OpenDatabase("D:\EA\DB\EA.mdb")
Set rs = db.OpenRecordset("Admission")
admissionsql = "SELECT  StudentID,StudentName" _
      & " FROM admission " _
      & "Order by StudentID"
   Set DataGrid1.DataSource = admissionssql
End Sub

What line does the error occurs.?

Make sure that all objects seen in your code are present in your form

(e.g DataGrid1).

Yes all objects are present on my form this line producing error

Set DataGrid1.DataSource = admissionssql

Hhhmm, i too recieve the error.

Try this:

1. Create a database connection module

Public Dbconn As New ADODB.Connection
Public rs As New ADODB.Recordset

Public Sub createlink()

Dbconn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
Dbconn.Open "EA.mdb"

End Sub

then

2. Replace your code with this:

Dim admissionsql As String          'General Declarations area

Private Sub Form_Load()

Dim db As ADODB.Connection
Dim rs As ADODB.Recordset

Call createlink


Set db = New ADODB.Connection
        db.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\EA.mdb"
        
        
Set rs = New ADODB.Recordset
        
        rs.Open "Select * From Admission", Dbconn, adOpenDynamic, adLockOptimistic

End Sub

This code will show all the records in your database in their respective column.

'Try this after the rs.Open...

Set DataGrid1.DataSource = rs.DataSource
DataGrid1.Datamember = rs.DataMember

This should have been the solution....

Set DataGrid1.DataSource = rs.Datasource

;)

Edited 5 Years Ago by AndreRet: n/a

This question has already been answered. Start a new discussion instead.