谁能帮我做一个VB连接access数据库的用户登录源代码,要可以注册的

如题所述

Private Sub Command1_Click()
Dim A As String
A = App.Path + "\ACCESS文件.mdb"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & A & ";Persist Security Info=False"
Adodc1.RecordSource = "SELECT * FROM 用户表 WHERE 用户名='" + 用户名 + "' AND 密码='" + 密码 + "'"
Adodc1.Refresh
If OT Adodc1.Recordset.EOF Then
主切面.Show
Me.Hide
Else
MsgBox ("用户名或密码错误!请重新输入!")
Me.用户名 = ""
Me.密码 = ""
'清空文本框内容
End If
End Sub
' 上面是登陆,把ACCESS建立在VB工程一个文件夹里取相对的路径
下面是注册用户表:
Private Sub Command2_Click()
Dim A As String
A = App.Path + "\ACCESS文件.mdb"
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & A & ";Persist Security Info=False"
Adodc1.RecordSource = "SELECT * FROM 用户表 "
Adodc1.Refresh
If OT Adodc1.Recordset.EOF Then
Adodc1.recordset.AddNew
Adodc1.recordset.fields("用户名")=文本框1
Adodc1.recordset.fields("密码")=文本框2
.....................
Adodc1.recordset.update
文本框1=""
文本框2=""
......
文本框1.setfocus
ELSE
文本框1=""
文本框2=""
.....
文本框1.setfoucus
end if
end sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-07-27
VB连接access数据库的用户登录源代码:

Dim conn As Data.OleDb.OleDbConnection
Dim provider As String
provider = "Provider=Microsoft.Jet.OLEDB.4.0"
Dim database As String
database = "Data Source=" & MapPath("..\") & "\Data数据库\ABC数据库.aspx;Persist Security Info=true"
conn = New Data.OleDb.OleDbConnection(provider & ";" & database)
conn.Open()
Dim sql As String
Dim cmd As Data.OleDb.OleDbCommand
'注意:此处需要加入防止注入分析,包含'的肯定是特别语句,讲拒绝.
If TextBox1.Text.IndexOf("'") > 0 Or TextBox2.Text.IndexOf("'") > 0 Then
TextBox1.Text = "不能输入非法字符,将强制清空"
TextBox2.Text = ""
Else
sql = "select 权限组号,ID from admin数据 where 编辑姓名='" + TextBox1.Text + "' and 密码='" + TextBox2.Text + "'"
cmd = New Data.OleDb.OleDbCommand(sql, conn)
cmd.ExecuteNonQuery()
Dim aa As Data.OleDb.OleDbDataReader = cmd.ExecuteReader
If aa.Read() Then
'密码正确()
Session("LOGIN_Name") = TextBox1.Text '设置登录后的用户名称
Session("Login_Group") = aa(0) 'cmd.ExecuteScalar '设置登录后的权限级别
Session("Login_ID") = aa(1) 'cmd.ToString
cmd = Nothing
conn.Close()
Response.Redirect("../WebManages/Default.ASPX")
'End If
' If cmd.ExecuteScalar Is Nothing Then
Else
'密码错误()
Label4.Visible = True
cmd = Nothing
conn.Close()
'MsgBox("您输入的密码错误,请重新输入!")
'Response.Redirect("/Default.ASPX")
End If
End If追问

用不了啊

追答

用不了?

你有数据库吗?

还有,数据库的字段是否对应修改过了呀。

对应的页面控件,是否也一致了呀。

本回答被网友采纳
相似回答