Getting information from the database
-
I want to create a Banking Management System, and i have created all the forms in vb.net 2003. The database is created using Microsoft Access 2003. I have stored the username and password of the customers in the table named customer details. This means that each time a user wants to login to this system, they have to enter their username and password and click the login button. Whatever they've entered will be checked with the database. If the information they have entered is correct, then they will be able to login. Else they would not be able to do so, and an error message will pop up. I want to know how should the code be written to be able to do as what i have explained above.
-
I want to create a Banking Management System, and i have created all the forms in vb.net 2003. The database is created using Microsoft Access 2003. I have stored the username and password of the customers in the table named customer details. This means that each time a user wants to login to this system, they have to enter their username and password and click the login button. Whatever they've entered will be checked with the database. If the information they have entered is correct, then they will be able to login. Else they would not be able to do so, and an error message will pop up. I want to know how should the code be written to be able to do as what i have explained above.
hope this little code will help you. here i am assuming that in 'customerdetails' table there are fields called 'uname' and 'pwd'. you call this function from you code and check for its return value, if it's true then the login is valid, or otherwise its invalid. for the ConStr property contain connectionstring that will be used to connect to the database, you can use something like this : 'provider=microsoft.jet.oledb.4.0;data source=d:\database\BankingMS.mdb' where you can replace 'd:\database\BankingMS.mdb' with you actual database location.
'before placing this code, make sure you have imported system.data.oledb
public function IsLoginValid(byval ConStr as string, byval UName as string, byval Password as string) as boolean
dim c as new oledbconnection(ConStr)
dim cmd as oledbcommand=c.createcommand
dim da as new oledbdataadapter(cmd)
dim dr as oledbdatareader
with cmd
.commandtext="select pwd from customerdetails where uname='" & _
uname.trim & "'"
try
dr=.executereader
catch x as exception
messagebox.show("Cant connect to database.")
finally
c.close
end try
end with
if dr.hasrows then
dr.read
if cstr(dr("pwd")).trim=password.trim then
return true
else
return false
end if
else
return false
end if
end function