使用acces的Visual Basic 2010登录表单 [英] a login form for visual basic 2010 using acces
问题描述
嘿,我编写了一个可以读取数据库的代码,但是我需要一个可以创建帐户"的按钮.并将详细信息保存到访问数据库中,以便可以登录.有人可以给我代码,还是可以将我链接到可以给我一个想法的站点:这里 到目前为止我的代码是
hey ive made a code that will read a database but i need a button that will "Create an account" and save the details into the access database so it can log in. could someone give me the code or preferably link me to a site which can give me an idea: here is my code so far
Imports System.Data.OleDb
Public Class Form1
Private Property Form1 As Object
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
' OK button
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source='C:\Users\jacob\Documents\myDB.mdb'")
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM userDetails WHERE userID = '" & userNameTextBox.Text & "' AND password = '" & passwordTextBox.Text & "' AND role = '" & ComboBox1.Text & "' ", con)
con.Open()
Dim sdr As OleDbDataReader = cmd.ExecuteReader()
' If the record can be queried, Pass verification and open another form.
If (sdr.Read() = True) Then
MessageBox.Show("The user is valid!")
Dim Form1 As New Form
Me.Close()
Else
MessageBox.Show("you got it wrong")
End If
End Sub
' Cancel button
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
推荐答案
你好jacobase,
Hello jacobase,
嘿,我编写了一个可以读取数据库的代码,但是我需要一个可以创建帐户"的按钮.并将详细信息保存到访问数据库中,以便可以登录.有人可以给我代码,还是可以将我链接到可以给我一个想法的站点:这里 到目前为止我的代码是
hey ive made a code that will read a database but i need a button that will "Create an account" and save the details into the access database so it can log in. could someone give me the code or preferably link me to a site which can give me an idea: here is my code so far
Imports System.Data.OleDbPublic Class Form1 Private Property Form1 As Object Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) End Sub ' OK button Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click Dim con As New OleDbConnection("Provider=Microsoft.jet.oledb.4.0;data source='C:\Users\jacob\Documents\myDB.mdb'") Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM userDetails WHERE userID = '" & userNameTextBox.Text & "' AND password = '" & passwordTextBox.Text & "' AND role = '" & ComboBox1.Text & "' ", con) con.Open() Dim sdr As OleDbDataReader = cmd.ExecuteReader() ' If the record can be queried, Pass verification and open another form. If (sdr.Read() = True) Then MessageBox.Show("The user is valid!") Dim Form1 As New Form Me.Close() Else MessageBox.Show("you got it wrong") End If End Sub ' Cancel button Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click Me.Close() End SubEnd Class
关注这些样本
http://www.youtube.com/watch?v=_Kdr_L_DFOI&feature=related
http://www.developerfusion.com/code/5040/login-form/
此致.
这篇关于使用acces的Visual Basic 2010登录表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!