Public Class Form1       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
    End Sub    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        cn.ConnectionString = "provider=Microsoft..OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication5\WindowsApplication5\database1.sdf"        Dim strSQL As String
        strSQL = "   SELECT   *   FROM   用户表   WHERE   用户名=   '" & TextBox1.Text & "'   AND   密码=   '" & TextBox2.Text & "'"
        If strSQL = 0 Then
            MsgBox("用户名不正确")
        Else
            Form2.Show()
            MsgBox("登录成功")        End If        
    End SubEnd Class
csdn上的资料基本查完了,各种写法都尝试了,怎么还是有问题

解决方案 »

  1.   

    可能是没有NULL值的输入判断吧
      

  2.   

    strSQL = " SELECT * FROM 用户表 WHERE 用户名= '" & TextBox1.Text & "' AND 密码= '" & TextBox2.Text & "'"
      If strSQL = 0字符型能与INT型比?
      

  3.   

    开始没有像复制的,后来实在不知道改哪里了才赋值的
    开始时这样的
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      cn.ConnectionString = "provider=Microsoft..OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication5\WindowsApplication5\database1.sdf"
       
    If "   SELECT   *   FROM   用户表   WHERE   用户名=   '" & TextBox1.Text & "'   AND   密码=   '" & TextBox2.Text & "'" Then
                Form2.Show()
    else msgbox(“失败”)
    endif
    endsub
      

  4.   

    IF " SELECT * FROM 用户表 WHERE 用户名= '" & TextBox1.Text & "' AND 密码= '" & TextBox2.Text & "'" 这是什么意思?IF应该是布尔表达式吧,
      

  5.   

    楼主的SQL语句都没有执行,你这样判断登录能行吗?执行SQL语句,判断返回行数,如果>0 就成功
      

  6.   

    Public Class Form1
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      End Sub  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      cn.ConnectionString = "provider=Microsoft..OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsApplication5\WindowsApplication5\database1.sdf"    '这里是不是还需要用户名和密码呢??
    '与数据库的连接不用打开就可以使用吗?VB 应该不会这么特殊吧...
      Dim strSQL As String
      strSQL = " SELECT * FROM 用户表 WHERE 用户名= '" & TextBox1.Text & "' AND 密码= '" & TextBox2.Text & "'"
      If strSQL = 0 Then   '这里少了个命令函数!
      MsgBox("用户名不正确")
      Else
      Form2.Show()
      MsgBox("登录成功")
      End If
      End Sub
    End Class