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 meSad) 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...

Code Block

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 form

Public Login_userlevelAsInteger' used to asign access levels

Public 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 MySqlConnection

Public connection_stringAsString

PublicSub Check_username()

Call Check_user()

EndSub

PrivateSub Check_user()

' generate script for checking for valid username :)

Login_Correct_username =False

' In here i need to compare the data in the table

Login_Correct_username =True

Call Check_password()

EndSub

PrivateSub Check_password()

'generate script for checking the password

Login_Correct_password =False

If Login_Correct_username =FalseThen

MsgBox("Sorry some of the details you have entered are inncorrect, please try again... Username...", MsgBoxStyle.Information,"Need Some Help?")

ExitSub

ElseIf Login_Correct_username =TrueThen

If Login_Correct_password =TrueThen

Login_User_ok =True

Else

Login_User_ok =False

MsgBox("Sorry some of the details you have entered are inncorrect, please try again... Password ...", MsgBoxStyle.Information,"Need Some Help?")

EndIf

EndIf

EndSub

EndModule

Code Block

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 MySqlConnection

ath_connection.ConnectionString = connection_string

lbl_status.Text ="Please Login..."

Me.ShowInTaskbar =True

EndSub

PrivateSub txt_username_TextChanged(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles txt_username.TextChanged

If txt_username.Text <>""Then

txt_password.Enabled =True

Else

txt_password.Enabled =False

txt_password.Text =""

EndIf

EndSub

PrivateSub btn_exit_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btn_exit.Click

Application.Exit()

ath_connection.Close()

ath_connection.Dispose()

EndSub

PrivateSub btn_login_Click(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles btn_login.Click

Try

lbl_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_db

ath_connection.Open()

lbl_status.Text ="Connection Successful..."

' need to locate how to access the table via vb.net

txt_username.Enabled =False

lbl_status.Text ="Checking User..."

' search the table for the username=? and on the same row password=?

Call Check_username()

If Login_User_ok =TrueThen

lbl_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 closes

Else

lbl_status.Text ="Failed To Login Under Those Details! The Controls Will Re-Enable Shortly..."

txt_username.Enabled =False

Timer.Start()

txt_username.Text =""

txt_password.Text =""

txt_username.Focus()

EndIf

Catch exAs Exception

MsgBox(Err.Description & Err.Source, MsgBoxStyle.Information,"Error...")

lbl_status.Text ="Please Login..."

txt_username.Text =""

txt_password.Text =""

txt_username.Focus()

EndTry

EndSub

PrivateSub Timer_Tick(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles Timer.Tick

lbl_status.Text ="Please Login..."

txt_username.Enabled =True

txt_username.Text =""

txt_password.Text =""

txt_username.Focus()

Timer.Stop()

EndSub

PrivateSub ToolStripContainer1_ContentPanel_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)

EndSub

PrivateSub ToolStripContainer2_ContentPanel_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)

EndSub

EndClass

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...Smile

[12746 byte] By [Stu...] at [2008-1-10]
# 1

I wish I had time to assist you but I don't.

But I VERY MUCH wanted to compliment you on the clearity and organization of your question!

ReneeC at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

I got this from someone a few months ago here in the forum

I haven't done any remote connections but this is along the lines of what you are looking for

Dim cn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb")

Dim cmd As New OleDb.OleDbCommand("Select count(id) from Users where UserID='" & Your User Name & "' AND Password='" & Your Password & "'", cn)

cn.Open()

If cmd.ExecuteScalar = 1 Then

'usr found

Else

'Invalid login

End If

js06 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3
cheers i shall try that later on Smile
Stu... at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...