i want to search data from access database and display it in datagrid.
please help me..
thanks in advanced....:)

see this code :

Dim sql As String
Private Sub ViewData()
    Set rs = New ADODB.Recordset
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Open "SELECT * FROM Login Where UserID = '" & txtUserId.Text & "' AND Password = '" & txtPasw.Text & "'", Conn, , , adCmdText
       
    Set DataGrid1.DataSource = rs
    DataGrid1.Columns(0).Width = 2000
    DataGrid1.Columns(1).Width = 2000
   
    DataGrid1.AllowAddNew = False
    DataGrid1.AllowArrows = True
    DataGrid1.AllowDelete = False
    DataGrid1.AllowUpdate = False
End Sub
Private Sub ViewData2()
    Set rs = New ADODB.Recordset
        rs.CursorType = adOpenDynamic
        rs.LockType = adLockOptimistic
        rs.Open "select * from Login ", Conn
       
    Set DataGrid1.DataSource = rs
    'DataGrid1.Columns(0).Width = 2000
    'DataGrid1.Columns(1).Width = 2000
   
    DataGrid1.AllowAddNew = False
    DataGrid1.AllowArrows = True
    DataGrid1.AllowDelete = False
    DataGrid1.AllowUpdate = False
End Sub
Private Sub btnView_Click()
Access_Connector
Call ViewData
End Sub

Private Sub Form_Load()
Access_Connector
ViewData2
End Sub

ok. Hope this Helps...
don't forget to give feedback...

Comments
great
awesome

hi jx_man...
thanks for your reply
i got error here and i guest it from the connection of this code.
may i see your connection code?

Ok. this my connection code.
and don't forget to add the procedure name if you want to call every function that it has connection to database.

Global Conn As ADODB.Connection
Global rs As ADODB.Recordset

Sub Access_Connector()
    Set Conn = New ADODB.Connection
        Conn.Provider = "microsoft.jet.oledb.4.0"
        Conn.CursorLocation = adUseClient
        Conn.Open App.Path & "\SIS.mdb"
End Sub

Hope this helps.

oh... yes, got it.
i will remember to call connector function.
thanks for your helping dude.

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