hi i have a table name table1 i want to display all the records in the table by using data grid and when i try to run it there is no records display in the datagrid and i have already configure the datalink which i name it adodc. could anyone let me know where i get wrong? here is my code. i name my data grid as dbgrid

Dim rec_rs As New ADODB.Recordset
Dim sql As String
Dim con As ADODB.Connection



Private Sub Form_Load()

    Set con = New ADODB.Connection
    
    
    con.Open "provider = microsoft.jet.oledb.4.0;persist security info = false; data source = " & App.Path & "\database1.mdb;"
    con.CursorLocation = adUseClient
    
    Set dbgrid.DataSource = Nothing
   
   
   
    sql = "select * from table1"
    
    rec_rs.Open sql, con, adOpenStatic, adLockOptimistic, adCmdText
    
   
    If rec_rs.EOF = False Then
        Set dbgrid.DataSource = rec_rs  
    End If
    rec_rs.Close
    
End Sub

i dont know how to use data grid hope i could you all can help me with this one..thanks.

Your call to set the datasource of the grid is in the incorrect place. You are calling it whilst you expect there to be no records.

If rec_rs.EOF = False Then
        Set dbgrid.DataSource = rec_rs  
    End If
    rec_rs.Close

'Change this to...

Set dbgrid.DataSource = rec_rs ' irrespective of data or not
'If rec_rs is an adodc control, use 
Set dbgrid.DataSource = rec_rs.Recordsource
    rec_rs.Close

Edited 5 Years Ago by AndreRet: n/a

do i have to erase the if statement?or just as is..i will try that one..i will keep in touch whatever the result. thanks andreret

i still didnt get any records, i already follow it. i want to get all the records inside my table directly to my datagrid but it does not show any records at all. what did i miss?

If rec_rs.EOF = False Then
        Set dbgrid.DataSource = rec_rs  
    End If
    rec_rs.Close

'Change this to...

Set dbgrid.DataSource = rec_rs ' irrespective of data or not
'If rec_rs is an adodc control, use 
Set dbgrid.DataSource = rec_rs.Recordsource
    rec_rs.Close

i still didnt get any records even i get the if clause and only remain the set dbgrid.DataSource

Edited 3 Years Ago by pyTony: fixed formating

i am using ado. i dont know how to use data control

Edited 5 Years Ago by androidz: n/a

Try replacing

con.Open "provider = microsoft.jet.oledb.4.0;persist security info = false; data source = " & App.Path & "\database1.mdb;"

to

con.Open "provider = microsoft.jet.oledb.4.0;data source = " & App.Path & "\database1.mdb; persist security info = false"

Try checking your ADO connection.

ok i will try that one..do i have to make datalink?and place it on the property of the data grid or not anymore?

You need to do this via code -

Set Datagrid1.Datasource = Rs 'where Rs is your recordsource holder
Set Datagrid1.Datasource = Rs 'where Rs is your recordsource holdee

what im trying to do is i declare my rec_rs on the top. dim rec_rs as new adodb.recordset i just want to get all the records in that table by using datagrid instead of flexgrid.. i dont know if im handling the code correctly cause still i didnt get any records at all when i run it.

Edited 3 Years Ago by pyTony: fixed format

Using adodc conncetion..

adodc1.conncetionstring = "Provider = Microsoft.jet.oledb.4.0;data source = "databasename.mdb;persist security info = false"

adodc1.recordsource = "Select * from table1"
adodc1.refresh

set datagrid1.datasource = adodc1

thats all..

As far as my knowledge goes, I am sure that when using the datacontrol (Adodc1), you have to do it this way -:)

Set Datagrid1.RecordSource = Adodc1.Recordsource

@AndroidZ, post the cirrent code you have to connect to your database AND the grid. In clude the table field names, lets see where your problem lies.:)

Dim sql As String
Dim con As ADODB.Connection
dim rec_rs as ADODB.recordset


Private Sub Form_Load()

    Set con = New ADODB.Connection
    set rec_rs = new ADODb.recordset
    
    con.Open "provider = microsoft.jet.oledb.4.0;persist security info = false; data source = " & App.Path & "\database1.mdb;"

    con.CursorLocation = adUseClient
    
    Set dbgrid.DataSource = Nothing
   
   
   
    sql = "select * from table1"
    
    rec_rs.Open sql, con, adOpenStatic, adLockOptimistic, adCmdText
    
   
   
        Set dbgrid.DataSource = rec_rs  'as you can see i extract the if clause
    
    rec_rs.Close
    
End Sub

is there any i have to set on the property of the data grid?cause i dont know what to set in the property of the data grid

table1 = 'this is where i want to get all the records

field1 as double this are all the fields that in my table
field2 as double
field3 as double

all i want is to get all the records in the table1..i am only using form_load
hope i give you it clearly tnx..^_^

Comments
:)

dont close the connection. and use

Set dbgrid.DataSource = rec_rs
rec_rs.requery

omit this

'rec_rs.close

thanks dspnhn it works..how can i add some rows in the datagrid?after the last record if ever i want to let the user input new record on it?

thanks again everyone

please mark this thread as solved and start another one with your query

Comments
Although my original, thanks fro seeing it through with the OP.:)
This question has already been answered. Start a new discussion instead.