In the forum, I often see some friends in the vb version asking questions about login. This article provides some help for beginners. Of course, I hope that experts with better methods can give advice.
First file → new → project select windows application and add two label controls, two textbox controls, and two buton controls on the form, such as (1-1 ):
After the interface is designed, write the following code in the button click event:
|
(Reference imports system. Data. oledb at the top of the Program) Private sub bok_click (byval sender as system. Object, byval e as system. eventargs) handles Bok. Click 'Definition Dim olecn as new oledbconnection ("provider = Microsoft. Jet. oledb.4.0; Data Source = data. mdb ") Dim olecm as new oledbcommand ("select * from login", olecn) Dim olead as new oledbdataadapter Dim olerd as oledbdatareader Dim PD as Boolean = false' is defined as Boolean for subsequent error handling. Dim I as integer Olecm = new oledbcommand ("select * from login", olecn) 'Establish a connection with the database Olecn. open () Olerd = olecm. executereader 'Cyclically determine whether the data in the database is the same Do While olerd. Read () For I = 0 to olerd. fieldcount-1 If trim (Tuser. Text) = (olerd. Item ("account") and trim (tpassword. Text) = (olerd. Item ("password") then Msgbox ("successfully logged on ") Pd = true Exit sub End if Next Loop Tuser. Text = "" Tpassword. Text = "" Tuser. Focus () Olerd. Close () Olecn. Close () End sub |
The whole process is complete.
QQ: 174453914