Results 1 to 4 of 4

Thread: ado connection and datagrid error

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    7

    ado connection and datagrid error

    recorded datas seem on datagrid on the connection in form_load procedure
    but when i connected to access database in text1_change procedure ,the datas are not being seemed,what is the problem or the code that ı didnt add?

    <code>



    (general declerations)
    ------------------------
    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset

    (form load)
    -----------

    Set rs = New ADODB.Recordset

    rs.Open "select * from abc order by a asc ", con, adOpenKeyset, adLockOptimistic
    Set DataGrid1.DataSource = rs

    set DataGrid1.Columns(0).Datafield="a"
    DataGrid1.Columns(0).Caption="a"
    set DataGrid1.Columns(0).Datafield="b"
    DataGrid1.Columns(0).Caption="b"
    set DataGrid1.Columns(0).Datafield="c"
    DataGrid1.Columns(0).Caption="c"
    Text1.Text = ""

    (text1_change)
    --------------
    Set rs = New ADODB.Recordset

    rs.Open "select * from abc where a like '"& text1.text & "%' order by a asc ", con, adOpenKeyset, adLockOptimistic
    Set DataGrid1.DataSource = rs

    --------------------------------------------------------------------------

  2. #2
    Lively Member
    Join Date
    Dec 2006
    Posts
    96

    Re: ado connection and datagrid error

    Hi,

    Try using this code......

    Code:
    'General Declaration
    Dim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    Private Sub Form_Load()
        con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\Temp.mdb;Persist Security Info=False"
        rs.CursorLocation = adUseClient
        rs.Open "select * from abc order by a asc", con, adOpenDynamic, adLockOptimistic
        Set DataGrid1.DataSource = rs
    End Sub
    
    Private Sub Text1_Change()
        If rs.State = 1 Then rs.Close
        rs.Open "select * from abc where a like '"& text1.text & "%' order by a asc ", con, adOpenDynamic, adLockReadOnly
        DataGrid1.ClearFields
        Set DataGrid1.DataSource = rs
    End Sub
    This will help u out..

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    7

    Re: ado connection and datagrid error

    thanks for your help friend,it is working now.. take care

  4. #4
    Lively Member
    Join Date
    Dec 2006
    Posts
    96

    Re: ado connection and datagrid error

    Hi,

    Just edit ur post and mark it as [RESOLVED]..

    Thanx
    Rahul Yadav

    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width