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
追问用不了啊
追答用不了?
你有数据库吗?
还有,数据库的字段是否对应修改过了呀。
对应的页面控件,是否也一致了呀。
本回答被网友采纳