0

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.

6
Contributors
18
Replies
23
Views
6 Years
Discussion Span
Last Post by Adrian779
Featured Replies
  • [CODE] 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 … Read More

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

0

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 by AndreRet: n/a

0

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

0

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?

0
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 by pyTony: fixed formating

0

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

Edited by androidz: n/a

0

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.

0

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?

0

You need to do this via code -

Set Datagrid1.Datasource = Rs 'where Rs is your recordsource holder
0
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 by pyTony: fixed format

0

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..
0

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.:)

1
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
:)
0

dont close the connection. and use

Set dbgrid.DataSource = rec_rs
rec_rs.requery

omit this

'rec_rs.close

0

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

1

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.