我刚学vb,试着写连接数据库的小程序,可执行时有语法错误,各位帮忙看看
建数据库test,表info,字段user,password
代码如下:
Private Sub Command1_Click()
    Set conn = New ADODB.Connection
    Set rs = New ADODB.Recordset
    Dim strsql As String
    conn.ConnectionString = "Driver=  {sqlserver};server=ldz;uid=sa;pwd=liudazhong;database=test"
    conn.Open   
    strsql = "select user,password from info where user = '" & Trim(Text1.Text) & "' , password = '" & Trim(Text2.Text) & "'"
    rs.Open strsql, conn, adOpenForwardOnly, adLockReadOnly   
    If rs.EOF Then
    MsgBox "检验错误", vbInformation, "提示"   
    End If      
End Sub运行时,当输入名字和密码,点确认时下面这句有错误
rs.Open strsql, conn, adOpenForwardOnly, adLockReadOnly   

解决方案 »

  1.   

    Set conn = New ADODB.Connection
        Set rs = New ADODB.Recordset
    改成
    dim conn as New ADODB.Connection
    dim rs as New ADODB.Recordset
      

  2.   

    strsql = "select user,password from info where user = '" & Trim(Text1.Text) & "' , password = '" & Trim(Text2.Text) & "'"
     user password 是关键字 应该加[]
    那个字段应该这么写
    strsql = "select user,password from info where [user] = '" & Trim(Text1.Text) & "' , [password] = '" & Trim(Text2.Text) & "'"
      

  3.   

    逗号好像不行,改为and吧^_^
    strsql = "select user,password from info where user = '" & Trim(Text1.Text) & "' and [password] = '" & Trim(Text2.Text) & "'"
      

  4.   

    strsql = "select password from info where user = '" & Trim(Text1.Text) & "'"