Student of vb + mysql
Hey there,
Cutting a long story short I am a computing student(just turned 18) working with visual studio to complete various projects in my course. However, in this (my last big project) I have seem to run into a little problem.
System Outline:
(Software)
Vista 64-bit (And XP SP2 32-Bit + below)
Visual Studio 2005
MySQL Connector/Net 5.1.3
MySQL Administration Tools.
The Problem:
I have another pc on my network running MySQL server. On that i have a database. Everything is working fine and i can connect to the server and login as either the root or admin (i created "admin"). The problem is that i cannot seem to access the table to read the data. This is a slight problem as i cannot continue with this project untill i get them to "login".
For them to "login", i store user_id (auto_increment, PK) username, password, user_level(boolean) in the table on the database. I need to check to see if the username and password match whats entered.
I think i could construct the rest of the code if i could search the database. Does anybody know how i could search the database?
The Code i have soo far:
The bits i need help with (as the internet has come up with no answers for me
) are the accessing the table and getting the first row of data so that i can see if that matches to varibles if not then get the next row...
Imports MySql.Data.MySqlClient
Imports MySql.Data.Types
Module Main
Public Login_usernameAsString' used to get the username from the login form
Public Login_passwordAsString' used to get rhe password from the login formPublic Login_userlevelAsInteger' used to asign access levelsPublic Login_Correct_usernameAsBoolean =False' is the username correct?Public Login_Correct_passwordAsBoolean =False' is the password correct?Public Login_User_okAsBoolean =False' if both the above are true then ...Public ath_connectionAsNew MySqlConnectionPublic connection_stringAsStringPublicSub Check_username()Call Check_user()EndSubPrivateSub Check_user()' generate script for checking for valid username :)Login_Correct_username =
False' In here i need to compare the data in the tableLogin_Correct_username =
TrueCall Check_password()EndSubPrivateSub Check_password()'generate script for checking the passwordLogin_Correct_password =
FalseIf Login_Correct_username =FalseThenMsgBox(
"Sorry some of the details you have entered are inncorrect, please try again... Username...", MsgBoxStyle.Information,"Need Some Help?")ExitSubElseIf Login_Correct_username =TrueThenIf Login_Correct_password =TrueThenLogin_User_ok =
TrueElseLogin_User_ok =
FalseMsgBox(
"Sorry some of the details you have entered are inncorrect, please try again... Password ...", MsgBoxStyle.Information,"Need Some Help?")EndIfEndIfEndSubEndModule
PublicClass Ath_db_login
PrivateSub Ath_db_login_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load
txt_password.Enabled =False
connection_string =
"server=" &My.Settings.hostip &"; user=*****; password=******; database=ath_db"ath_connection =
New MySqlConnectionath_connection.ConnectionString = connection_string
lbl_status.Text =
"Please Login..."Me.ShowInTaskbar =TrueEndSubPrivateSub txt_username_TextChanged(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles txt_username.TextChangedIf txt_username.Text <>""Thentxt_password.Enabled =
TrueElsetxt_password.Enabled =
Falsetxt_password.Text =
""EndIfEndSubPrivateSub btn_exit_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btn_exit.ClickApplication.Exit()
ath_connection.Close()
ath_connection.Dispose()
EndSubPrivateSub btn_login_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btn_login.ClickTrylbl_status.Text =
"Commencing Connection..."ath_connection.Close()
ath_connection.Dispose()
Login_username = txt_username.Text
Login_password = txt_password.Text
' link to mysql server opens here > also access ath_dbath_connection.Open()
lbl_status.Text =
"Connection Successful..."' need to locate how to access the table via vb.nettxt_username.Enabled =
Falselbl_status.Text =
"Checking User..."' search the table for the username=? and on the same row password=?Call Check_username()If Login_User_ok =TrueThenlbl_status.Text =
"Welcome " & Login_username &". Have a nice stay."txt_username.Text =
""txt_password.Text =
""txt_username.Focus()
Main_menu.Show()
Me.Enabled =False'then main menu opens, and after period of 5 seconds (500ms) then login form closesElselbl_status.Text =
"Failed To Login Under Those Details! The Controls Will Re-Enable Shortly..."txt_username.Enabled =
FalseTimer.Start()
txt_username.Text =
""txt_password.Text =
""txt_username.Focus()
EndIf Catch exAs ExceptionMsgBox(Err.Description & Err.Source, MsgBoxStyle.Information,
"Error...")lbl_status.Text =
"Please Login..."txt_username.Text =
""txt_password.Text =
""txt_username.Focus()
EndTryEndSubPrivateSub Timer_Tick(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Timer.Ticklbl_status.Text =
"Please Login..."txt_username.Enabled =
Truetxt_username.Text =
""txt_password.Text =
""txt_username.Focus()
Timer.Stop()
EndSubPrivateSub ToolStripContainer1_ContentPanel_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)EndSubPrivateSub ToolStripContainer2_ContentPanel_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)EndSubEndClass
The above code is not very advanced as i do not know the language very well...
Any assistance would be greatly appricated (*'d out network info for security)
Thanks in advance
Stu...![]()

