鼠标选中listbox中任意一行,然后按此行内容
查数据库,内容(可能多行)显示到另外一个listbox中
具体如何做?
在:Private Sub List1_Click()中写 ,还是??

解决方案 »

  1.   

    Private Sub List1_Click()
    Dim strSql as string
    dim myRs as New ADODB.Recordset
    dim Connstr as string
    Connstr="......"         '连接数据库的字符串
    strSql ="Select * From Table WHere Name='" & List1.Text & "'"
    myrs.open strsql,Connstr
    list2.clear
    do while not myrs.eof 
      list2.additem myrs.fields(0).values       '或者其它列也可以
      myrs.movenext
    loop
    myrs.close
    End Sub
      

  2.   

    Private Sub List1_Click()
    Dim strSql as string
    dim myRs as New ADODB.Recordset,dim conn as new adodb.connection
    dim Connstr as string
    Connstr="......"         '连接数据库的字符串
    conn.open Connstr
    strSql ="Select * From Table1 WHere Name='" & List1.Text & "'"
    myRs.open strsql,Conn
    list2.clear
    do while not myrs.eof 
      list2.additem myrs.fields(0).values       '或者其它列也可以
      myrs.movenext
    loop
    myrs.close
    conn.close
    End Sub
      

  3.   

    来了 来了,怎么两个回答都一样? 呵呵
    哦看错
    clear_zero(清晰)兄: 
       myrs.close
       conn.close这样和只写
        myrs.close
    区别在哪里?另外:
    随用随创建 
    New ADODB.Recordset 和 new adodb.connection
    会不会影响速度?
      

  4.   

    如果只是查询记录,可以只定义Recordset,connection可以省略如果你的查询是频繁的,也可以将myRs定义为公共变量,但每次执行完后,必须执行myRs.Close,否则可能会出现错误