我想用ado+dataGrid 实现如下功能(数据库是SQL Server 要操作的表有编号 名称 数量等信息)
1。在一个文本框中输入编号 点击确定后能在dataGrid中显示出此编号对应的详细信息2。重复1  所得的记录添加在dataGrid 的下一行 请教 最好有代码 多谢多谢

解决方案 »

  1.   

    没执行一次1就重新查数据库然后把结果赋给DATAGRID从第二次开始查询的SQL语句要和前面的用UNION起来
      

  2.   

    '引用microsoft activex data object 2.x library
    Option Explicit
    Private conn As ADODB.Connection
    Private rs As ADODB.RecordsetPrivate Sub Command1_Click()Dim apppath As String
    Dim dbfilename As String
    Dim ConnectString As String
    Dim i As Integer
    Set conn = New ADODB.Connection
    If Right(App.Path, 1) = "\" Then
       apppath = App.Path
    Else
       apppath = App.Path & "\"
    End If
    dbfilename = apppath & "order.mdb"
    ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbfilename & ";Persist Security Info=False;"
    conn.Open ConnectString
    conn.CursorLocation = adUseClientSet rs = New ADODB.Recordset
    rs.Open "select * from orders where id="& val(text1.text), conn, adOpenDynamic, adLockPessimistic
    If rs.EOF Then
    Exit Sub  
    End IfSet DataGrid1.DataSource = rs
    End Sub