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上的资料基本查完了,各种写法都尝试了,怎么还是有问题
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上的资料基本查完了,各种写法都尝试了,怎么还是有问题
If strSQL = 0字符型能与INT型比?
开始时这样的
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
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