小弟初学,请指教,想建立一个很简单的VB程序连接数据库Private Sub Command1_Click()
   Dim Conn As New ADODB.Connection
   Dim sql1 As String
   Conn.ConnectionString = "Driver={SQL Server};Server=SAM-NOTEPAD;Uid=sa;Pwd=sakura11;Database=mxb-ms"
   Conn.Open
   sql1 = "select * from table1"
   如何把select后得到的数据,赋值到VB中的一个变量。。比如a1中去
应该是有一个RS数据集之类的,请指教,谢谢!
   Conn.Close
End Sub

解决方案 »

  1.   

    Private Sub Command1_Click()
      Dim Conn As New ADODB.Connection
      dim rs as new adodb.recordset
      Dim sql1 As String
      Conn.ConnectionString = "Driver={SQL Server};Server=SAM-NOTEPAD;Uid=sa;Pwd=sakura11;Database=mxb-ms"
      Conn.Open
      sql1 = "select aa from table1"
      if rs.state<>adstateclosed then rs.close
      rs.open sql1,conn,adopenkeyset,adlockreadonly
      if rs.recordcount>0 then
          a1=rs!aa &""
      endif
      rs.close  
      Conn.Close
    End Sub
      

  2.   

     a1=rs!aa &"" 这一句不太懂
      

  3.   

    Private Sub Command1_Click()
      Dim Conn As New ADODB.Connection
      dim a1 as new adodb.recordset
      Dim sql1 As String
      Conn.ConnectionString = "Driver={SQL Server};Server=SAM-NOTEPAD;Uid=sa;Pwd=sakura11;Database=mxb-ms"
      Conn.Open
      sql1 = "select aa from table1"
      if a1.state<>adstateclosed then a1.close
      a1.open sql1,conn,adopenkeyset,adlockreadonly
      if a1.recordcount>0 then
      a1=a1!aa &""
      endif
      a1.close   
      Conn.Close
    End Sub
          
                
      

  4.   

    dim rs as new ADODB.RecordSet
    a=rs.fields("需要操作的字段名").value通过rs 去操作
      

  5.   

    碰到一个问题a1=rs!aa &""如果aa字段里面有很多数据,如果一个一个引用?