VB设置注册用户要判断在ACCESS里面用户是否已存在,该在哪里添加那些代码?
数据库log.mdb,表名login,表里用户保存列名username,密码保存列名password。注册窗体Command1_Click()代码如下:PrivateSu...
数据库log.mdb,表名login,表里用户保存列名username,密码保存列名password。
注册窗体Command1_Click()代码如下:
Private Sub Command1_Click()
centerform Me
If Text1 = "" Then
MsgBox "请输入账号!", vbCritical, "错误"
Else
If Text1 <> "" And Text2 = "" Or Text3 = "" Then
MsgBox "请输入密码!", vbCritical, "错误"
Else
If Text2.Text <> Text3.Text Then
MsgBox "两次输入密码不一致!", vbCritical, "错误"
Else
If Text2.Text = Text3.Text Then
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
Unload Me
End If
End If
End If
End If
End Sub 展开
注册窗体Command1_Click()代码如下:
Private Sub Command1_Click()
centerform Me
If Text1 = "" Then
MsgBox "请输入账号!", vbCritical, "错误"
Else
If Text1 <> "" And Text2 = "" Or Text3 = "" Then
MsgBox "请输入密码!", vbCritical, "错误"
Else
If Text2.Text <> Text3.Text Then
MsgBox "两次输入密码不一致!", vbCritical, "错误"
Else
If Text2.Text = Text3.Text Then
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
Unload Me
End If
End If
End If
End If
End Sub 展开
1个回答
展开全部
只要写在连接数据库后,注册前就行吧
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
——————————————————————————————————————————
rs.Open "SELECT * FROM login where username='" & Text1 & "'", conn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
MsgBox "用户名已存在!", vbCritical, "错误"
rs.Close
Exit Sub
End If
rs.Close
——————————————————————————————————————————
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
Dim conn As ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Set conn = CreateObject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\log.mdb "
——————————————————————————————————————————
rs.Open "SELECT * FROM login where username='" & Text1 & "'", conn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
MsgBox "用户名已存在!", vbCritical, "错误"
rs.Close
Exit Sub
End If
rs.Close
——————————————————————————————————————————
sql = "select * from login"
rs.CursorLocation = adUseClient
rs.Open sql, conn, adOpenKeyset, adLockPessimistic
rs.AddNew
rs.Fields("username").Value = Text1.Text
rs.Fields("password").Value = Text2.Text
rs.Update
rs.Close
conn.Close
MsgBox "注册成功,返回登陆界面!", vbExclamation, "提示"
Form1.Show
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询