Dim loginerror As String 'This will tell the user what is going wrong with his/her
'Login.
Public Function Login() 'Name the Login section whatever you want, does not really
'Matter
Dim DBConn As New ADODB.Connection 'This is how we tell Visual Studio how to connect
'To our database
Dim User As New ADODB.Recordset 'We pass our arguments through our recordset.
Dim Username As String 'This will be our "Query"
Dim userDB As String 'This gets set to the Username field of our database
Dim passDB As String 'Same as above except for the Password field.
Dim UserFound As Boolean 'We will be using a Do Loop so we use this as our
'Condition.
'Lets open our connections
DBConn.Open("Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = '" & Application.StartupPath & "LoginDB.mdb'")
'The inverted comas in the data source statement are important as it keeps the
'location of your file as one string.
'This is our table /, / This is our connection,/ These are some settings, Have them as I have /
User.Open("UserTable", DBConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
UserFound = False
Login = False
Username = "Username = '" & txtUser.Text & "'" 'This statement tells the database to
'find the username field equivelant to what is entered in the textbox.
Do
User.Find(Username) 'This is the full statement that sends our "Query"
'To the recordset
If User.BOF = False And User.EOF = False Then
'BOF and EOF = Beggining of File
'And End of file, It tests whether the database has reached its sentinel
'Value, if it hasnt then the username has been found, if it has
'The username is invalid.
userDB = User.Fields("Username").Value.ToString
'"Username" is our table field. we are setting userDB to the Username
'Field of our table
'*Note* if writing TO the database do not use ToString simply use
'User.Fields("Username").Value = txtUser.Text
passDB = User.Fields("Password").Value.ToString
If userDB txtUser.Text Then
User.MoveNext()
'This IF STATEMENT handles different CASE usernames
'Example, admin and AdMiN
'We use this if statement to differentiate between different Case letters
Else
UserFound = True
If passDB = txtPass.Text Then
'DO NOT FORGET TO CLOSE YOUR CONNECTIONS
loginerror มัวเป็นสตริง'นี้จะบอกให้ผู้ใช้สิ่งที่จะผิดกับการที่เขา/เธอ
ตามมาตรฐาน'ล็อกอิน.
สาธารณะหน้าล็อกอิน()"ชื่อล็อกอินส่วนไม่ว่าคุณต้องการ,ไม่ได้จริงๆ
ตามมาตรฐาน"เรื่องของ เรื่อง
dbconn มัวเป็นใหม่ ADODB .การเชื่อมต่อ"นี้มีวิธีที่เราบอก Visual Studio ได้อย่างไรในการเชื่อมต่อ
'กับเรามัว ฐานข้อมูล
ผู้ใช้ใหม่ ADODB . Recordset 'ของเราเราจะผ่านอาร์กิวเมนต์ผ่านของเรา Recordset .
หรี่ลงชื่อผู้ใช้เป็นสตริง"แห่งนี้จะเป็นของเรา"คำถาม"
userdb มัวเป็นสตริง"แห่งนี้จะได้รับในฟิลด์ชื่อผู้ใช้ของเรามัวฐานข้อมูล
ตามมาตรฐาน passdb เป็นสตริง"เหมือนกับด้านบนยกเว้นสำหรับฟิลด์รหัสผ่าน.
userfound มัวเป็น'เราจะใช้ที่ทำการต่อพ่วงดังนั้นเราจึงใช้นี้เป็นของเรา
' สภาพ .
'ช่วยให้เปิดให้บริการของเราการ เชื่อมต่อ
dbconn .เปิดให้บริการ(“ผู้ให้บริการ= MICROSOFT . Jet Clean System . oledb. 4.0 ;"&_
"ที่มาของข้อมูล=""&แอปพลิเคชัน. startuppath &" logindb .;'")
'ที่ติดตั้งแบบกลับด้าน comas ในที่ที่มาของข้อมูลใบแจ้งยอดบัญชีมีความสำคัญที่จะตอบแทน
'ที่ตั้งของของคุณไฟล์เป็นสตริง.
'แห่งนี้เป็นของเราตาราง/,/แห่งนี้เป็นของเราการเชื่อมต่อ,/เหล่านี้เป็นการตั้งค่าที่ได้เป็นผมมี/
ผู้ใช้.เปิดให้บริการ(" usertable ", dbconn , ADODB . cursortypeenum . adopenstatic , ADODB . locktypeenum . adlockoptimistic )
userfound =ผิดพลาด
ตามมาตรฐานล็อกอิน=ผิดพลาดชื่อผู้ใช้="ชื่อผู้ใช้=""& txtuser .ข้อความ&""แห่งนี้แถลงการณ์บอกให้ที่ฐานข้อมูลที่จะตอบแทน
'ค้นหาชื่อผู้ใช้ฟิลด์ที่ equivelant ในที่ใส่ในกล่องข้อความที่.
ตามมาตรฐานหรือไม่ผู้ใช้ค้นหา(ชื่อผู้ใช้)"ซึ่งเป็นแบบเต็มใบแจ้งยอดบัญชีที่จะส่งของเรา"คำถาม"
'ที่ Recordset
ตามมาตรฐานหากผู้ใช้. bof =ความผิดพลาดและผู้ใช้โพรเซส=ผิดพลาดแล้ว
ตามมาตรฐาน" bof และโพรเซส= beggining ของไฟล์
ตามมาตรฐาน"และสิ้นสุดของไฟล์,ไม่ว่าจะเป็นการทดสอบที่ฐานข้อมูลมีไปถึงมือยาม
'ค่า,หากขาวๆแล้วชื่อผู้ใช้มีการพบว่ามี
ตามมาตรฐาน"ที่ชื่อผู้ใช้ไม่ถูกต้อง.
userdb =ผู้ใช้ฟิลด์ต่างๆ("ชื่อผู้ใช้")..ค่า. tostring
ตามมาตรฐาน""ชื่อผู้ใช้"เป็นของเราตารางฟิลด์.เรามีการตั้งค่า userdb
ตามมาตรฐานที่ชื่อผู้ใช้'ฟิลด์ของโต๊ะ
'*หมายเหตุ*หากการเขียนข้อมูลลงในฐานข้อมูลไม่ใช้ tostring เลือกใช้
'ผู้ใช้ฟิลด์("ชื่อผู้ใช้")= txtuser .ข้อความ
passdb =ผู้ใช้ฟิลด์ต่างๆ("รหัสผ่าน").ค่า. tostring
หาก userdb <> txtuser .ข้อความแล้ว
ตามมาตรฐานผู้ใช้. movenext ()
'นี้หากงบจัดการแตกต่างกันกรณีชื่อผู้ใช้
'ตัวอย่างเช่น,และการดูแลระบบผู้ดูแลระบบ
ตามมาตรฐาน"เราใช้แบบนี้ถ้างบในการสร้างความแตกต่างให้กับระหว่างกรณีจดหมาย
ตามมาตรฐานอื่น userfound =จริง
ตามมาตรฐานหาก passdb = txtpass .ข้อความแล้ว
'ต้องไม่ลืมปิดการเชื่อมต่อของคุณ
การแปล กรุณารอสักครู่..
![](//thimg.ilovetranslation.com/pic/loading_3.gif?v=b9814dd30c1d7c59_8619)