财叔之横扫千军 下载:用VB做的登陆验证界面,总是出错
来源:百度文库 编辑:神马品牌网 时间:2024/08/27 03:55:03
用ADO方式连接的数据库,总是出现一些问题
请高手帮忙看看
数据库名:access
表名:user
字段名:username password
完整代码如下:
Private Sub Command1_Click()
'¶¨Òå±äÁ¿£¬·Ö±ð¼Ç¼text1ºÍtext2µÄÄÚÈÝ
Dim su As String
su = Text1.Text
Dim sp As String
sp = Text2.Text
'¶¨Òå±äÁ¿£¬¼Ç¼sql²éѯ×Ö·û´®
Dim connstr As String
connstr = "select username from user where username='&su&' and password='&sp&'"
'²Ù×÷connection¶ÔÏó
Dim conn As New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=g:\vbtest\access.mdb;Persist Security Info=False"
conn.Open
'²Ù×÷command¶ÔÏó
Dim cmd As New ADODB.Command
cmd.CommandText = connstr
cmd.ActiveConnection = conn
'²Ù×÷recordset¶ÔÏó
Dim rs As New ADODB.Recordset
rs.Open connstr, conn, adOpenDynamic, adLockOptimistic, adCmdText
'µÇ½ÑéÖ¤
If Text1.Text = "" Then
MsgBox "Óû§ÃûΪ¿Õ£¬ÇëÖØÊÔ"
Text2.Text = ""
Text1.SetFocus
Exit Sub
Else
If Not Trim(Text1.Text) = rs.Fields(0).Name Then
rs.MoveNext
Exit Sub
Else
If Not Trim(Text2.Text) = rs.Fields(1).Value Then
MsgBox "ÊäÈëµÄÃÜÂëÓëÓû§Ãû²»Æ¥Å䣬ÇëÖØÊÔ"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Else
Unload Me
Form2.Show
End If
End If
End If
End Sub
Private Sub Command2_Click()
End
End Sub
那些乱码的地方是汉字
请高手帮忙看看
数据库名:access
表名:user
字段名:username password
完整代码如下:
Private Sub Command1_Click()
'¶¨Òå±äÁ¿£¬·Ö±ð¼Ç¼text1ºÍtext2µÄÄÚÈÝ
Dim su As String
su = Text1.Text
Dim sp As String
sp = Text2.Text
'¶¨Òå±äÁ¿£¬¼Ç¼sql²éѯ×Ö·û´®
Dim connstr As String
connstr = "select username from user where username='&su&' and password='&sp&'"
'²Ù×÷connection¶ÔÏó
Dim conn As New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=g:\vbtest\access.mdb;Persist Security Info=False"
conn.Open
'²Ù×÷command¶ÔÏó
Dim cmd As New ADODB.Command
cmd.CommandText = connstr
cmd.ActiveConnection = conn
'²Ù×÷recordset¶ÔÏó
Dim rs As New ADODB.Recordset
rs.Open connstr, conn, adOpenDynamic, adLockOptimistic, adCmdText
'µÇ½ÑéÖ¤
If Text1.Text = "" Then
MsgBox "Óû§ÃûΪ¿Õ£¬ÇëÖØÊÔ"
Text2.Text = ""
Text1.SetFocus
Exit Sub
Else
If Not Trim(Text1.Text) = rs.Fields(0).Name Then
rs.MoveNext
Exit Sub
Else
If Not Trim(Text2.Text) = rs.Fields(1).Value Then
MsgBox "ÊäÈëµÄÃÜÂëÓëÓû§Ãû²»Æ¥Å䣬ÇëÖØÊÔ"
Text1.SetFocus
Text1.Text = ""
Text2.Text = ""
Else
Unload Me
Form2.Show
End If
End If
End If
End Sub
Private Sub Command2_Click()
End
End Sub
那些乱码的地方是汉字
乱码