在VB中使用ADO与Access数据库 建立登录对话窗体:
Access中建立数据库:testdb.mdb 表 user 属性 user_account,user_password
vb工程中代码如下:
Option Explicit
Dim result As IntegerPrivate Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "用户名/密码不能为空"
Exit Sub
End If
result = UserValidate(Text1.Text, Text2.Text)
If result = 0 Then
Unload Me
Else
Select Case result
Case 1:
MsgBox "用户" & frmLogin.Text1 & "不存在"
Case 2:
MsgBox "用户" & frmLogin.Text1 & "密码错误"
Case Else
MsgBox "为知错误"
End Select
End If
End SubPrivate Sub Command2_Click()
End
End SubFunction UserValidate(input_user As String, input_password As String) As Integer
Dim rs As New ADODB.Recordset
Dim sql As String
Dim tmp_password As String
Dim conn As New ADODB.Connection
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source= " & App.Path & "\testdb.mdb;persist security info=false"
conn.Open
rs.ActiveConnection = conn
sql = "select user_account,user_password FROM user where user_account ='" & input_user & "'"
Call rs.Open(sql, conn)
If (rs.EOF) Then
UserValidate = 1
rs.Close
conn.Close
Exit Function
End If
tmp_password = rs("user_password")
rs.Close
conn.Close
If StrComp(tmp_password, input_password) Then
UserValidate = 2
Exit Function
End If
UserValidate = 0
End FunctionPrivate Sub Form_Load()
result = -1
End Sub
Private Sub form_unload(cancel As Integer)
If (Not result) Then
frmMain.Show
End If
End Sub每次按F5调试,输入正确的用户名和密码总是返回错误信息:“Form 子句语法错误” 但我看不出哪错,到底错在哪呢?
Access中建立数据库:testdb.mdb 表 user 属性 user_account,user_password
vb工程中代码如下:
Option Explicit
Dim result As IntegerPrivate Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Then
MsgBox "用户名/密码不能为空"
Exit Sub
End If
result = UserValidate(Text1.Text, Text2.Text)
If result = 0 Then
Unload Me
Else
Select Case result
Case 1:
MsgBox "用户" & frmLogin.Text1 & "不存在"
Case 2:
MsgBox "用户" & frmLogin.Text1 & "密码错误"
Case Else
MsgBox "为知错误"
End Select
End If
End SubPrivate Sub Command2_Click()
End
End SubFunction UserValidate(input_user As String, input_password As String) As Integer
Dim rs As New ADODB.Recordset
Dim sql As String
Dim tmp_password As String
Dim conn As New ADODB.Connection
conn.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source= " & App.Path & "\testdb.mdb;persist security info=false"
conn.Open
rs.ActiveConnection = conn
sql = "select user_account,user_password FROM user where user_account ='" & input_user & "'"
Call rs.Open(sql, conn)
If (rs.EOF) Then
UserValidate = 1
rs.Close
conn.Close
Exit Function
End If
tmp_password = rs("user_password")
rs.Close
conn.Close
If StrComp(tmp_password, input_password) Then
UserValidate = 2
Exit Function
End If
UserValidate = 0
End FunctionPrivate Sub Form_Load()
result = -1
End Sub
Private Sub form_unload(cancel As Integer)
If (Not result) Then
frmMain.Show
End If
End Sub每次按F5调试,输入正确的用户名和密码总是返回错误信息:“Form 子句语法错误” 但我看不出哪错,到底错在哪呢?
解决方案 »
- 急!!!!!!在VB中通过输入两个值怎么读取execl表中的值?
- 将多个txt文件拖入FileListBox时报错
- MonthView控件KeyPress为什么不能用。
- (ADO对象的用法)我要更新记录,可是弄不好,懂的人进来看看,谢谢!
- 怎样把鼠标图标 换成我自己准备好的图标或位图
- 谁有Crystal reports 9.0开发版的中文版啊.有没得下载地址啊.
- 各位英雄!!帮忙拉!!!100分!!关于播放器(比较特殊)!!
- 很简单,在线等待!
- 用VB调用DLL时,在参数中传递数据老出问题!!!
- 一段小程序,拉到启动里重启后就不正常了
- 如何将我的程序依附在其它文件上,打开其它文件时将先调用我的程序,别误会,我只想编个文件加密程序???
- 如何在vb中调用其他软件制作的com组件?
'尽量少用系统关键字(user为系统关键字)