VB.NET Selecting datatable for Login verification
-
Hello all, I'm trying to create a user login verification for my Window Form Application using VB.NET 2003 connect with MySQL 5.0 database. When the login form load,I have load all the USERID,USERNAME and USERPASSWORD into a dataset and put into a datatable name"cashier" shown inside my code below:
ObjConn = New OdbcConnection(Connect())
ObjComm = New OdbcCommand("SELECT * FROM pos_cashier WHERE LocationCode='" & TerminalLocate & "'", ObjConn)ObjConn.Open()
ObjAdapter.SelectCommand = ObjComm
ObjAdapter.Fill(DS, "cashier")
DT = DS.Tables("cashier")
ObjConn.Close()Now I need someone can guide me how to select a row or column inside this datatable so I can check the user login name and password are same with what inside this cashier datatable which used to authorise user login. What I wish to do is something as follow: If textbox1.text = datatable.cashier.USERNAME Then If textbox2.text = datatable.cashier.USERPASSWORD Then UserloginSuccess = True Dim MainForm as new MainForm Me.Hide() MainForm.Show() Else Messagebox.show("Sorry,Wrong Password") End If Else Messagebox.Show("Sorry,Username not available on the system.") End IF Anyone can give me some help about selecting this datatable? Thank you for reading. Regards Drex
-
Hello all, I'm trying to create a user login verification for my Window Form Application using VB.NET 2003 connect with MySQL 5.0 database. When the login form load,I have load all the USERID,USERNAME and USERPASSWORD into a dataset and put into a datatable name"cashier" shown inside my code below:
ObjConn = New OdbcConnection(Connect())
ObjComm = New OdbcCommand("SELECT * FROM pos_cashier WHERE LocationCode='" & TerminalLocate & "'", ObjConn)ObjConn.Open()
ObjAdapter.SelectCommand = ObjComm
ObjAdapter.Fill(DS, "cashier")
DT = DS.Tables("cashier")
ObjConn.Close()Now I need someone can guide me how to select a row or column inside this datatable so I can check the user login name and password are same with what inside this cashier datatable which used to authorise user login. What I wish to do is something as follow: If textbox1.text = datatable.cashier.USERNAME Then If textbox2.text = datatable.cashier.USERPASSWORD Then UserloginSuccess = True Dim MainForm as new MainForm Me.Hide() MainForm.Show() Else Messagebox.show("Sorry,Wrong Password") End If Else Messagebox.Show("Sorry,Username not available on the system.") End IF Anyone can give me some help about selecting this datatable? Thank you for reading. Regards Drex
You can use
DataTable.Select()
method. It returnsDataRow
array.drexler_kk wrote:
When the login form load,I have load all the USERID,USERNAME and USERPASSWORD into a dataset and put into a datatable name"cashier"
It's bad design. Why don't you do user verification in the database when user clicks the login button ? When you are loading all the data to dataset on form load, your application will take long time to load when there are more number of users.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
You can use
DataTable.Select()
method. It returnsDataRow
array.drexler_kk wrote:
When the login form load,I have load all the USERID,USERNAME and USERPASSWORD into a dataset and put into a datatable name"cashier"
It's bad design. Why don't you do user verification in the database when user clicks the login button ? When you are loading all the data to dataset on form load, your application will take long time to load when there are more number of users.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
Sorry,can you give me some sample how should I used this DataTable.Select() method? Hello Navaneeth, I have try to change it to the following code but it doesn't work.
For i = 0 to DT.Rows(i).Count - 1
If Test =DT.Select("USERNAME='"& textbox1.text &"'")(i) Then
If DT.Select("USERPASSWORD='" & textbox2.text &"'")(i) ThenUserloginSuccess = True Dim MainForm as new MainForm Me.Hide() MainForm.Show() Exit For Else Messagebox.show("Sorry,Wrong Password!") End If
Else
Messagebox.show("Sorry,Username not available on ths system.")
End IfNext
The code above can't work. Can you tell me how to fixed it? Besides,what do you mean by do the user verification in the database? You mean directly use a SELECT statement which depend on the username and userpassword from the server to check if the server have the username with the right password?? Thanks for reading everyone,hope to hear from you all again soon. Regards Drex
-
Sorry,can you give me some sample how should I used this DataTable.Select() method? Hello Navaneeth, I have try to change it to the following code but it doesn't work.
For i = 0 to DT.Rows(i).Count - 1
If Test =DT.Select("USERNAME='"& textbox1.text &"'")(i) Then
If DT.Select("USERPASSWORD='" & textbox2.text &"'")(i) ThenUserloginSuccess = True Dim MainForm as new MainForm Me.Hide() MainForm.Show() Exit For Else Messagebox.show("Sorry,Wrong Password!") End If
Else
Messagebox.show("Sorry,Username not available on ths system.")
End IfNext
The code above can't work. Can you tell me how to fixed it? Besides,what do you mean by do the user verification in the database? You mean directly use a SELECT statement which depend on the username and userpassword from the server to check if the server have the username with the right password?? Thanks for reading everyone,hope to hear from you all again soon. Regards Drex
If you look at the documentation[^], it would be easy.
drexler_kk wrote:
For i = 0 to DT.Rows(i).Count - 1
No need of loop here.
Select()
returns aDataRow
array.drexler_kk wrote:
If Test =DT.Select("USERNAME='"& textbox1.text &"'")(i) Then
This is wrong.
Test =DT.Select("USERNAME='"& textbox1.text &"'")
.Test
should be DataRow array.drexler_kk wrote:
Besides,what do you mean by do the user verification in the database? You mean directly use a SELECT statement which depend on the username and userpassword from the server to check if the server have the username with the right password??
Yes. That would be faster than the method you are using. When user clicks on the login button, supply the user details entered to the database. Run a query to select the details. If everything is OK, proceed with login, else display error. Hope this helps
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
If you look at the documentation[^], it would be easy.
drexler_kk wrote:
For i = 0 to DT.Rows(i).Count - 1
No need of loop here.
Select()
returns aDataRow
array.drexler_kk wrote:
If Test =DT.Select("USERNAME='"& textbox1.text &"'")(i) Then
This is wrong.
Test =DT.Select("USERNAME='"& textbox1.text &"'")
.Test
should be DataRow array.drexler_kk wrote:
Besides,what do you mean by do the user verification in the database? You mean directly use a SELECT statement which depend on the username and userpassword from the server to check if the server have the username with the right password??
Yes. That would be faster than the method you are using. When user clicks on the login button, supply the user details entered to the database. Run a query to select the details. If everything is OK, proceed with login, else display error. Hope this helps
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
Hello Navaneeth, Yeah,thanks my friend. I have solve this problem by checking the site you provide. Thank You so much for the information and advice share me. Have a wonderful day. Regards Drex ;)
-
Hello Navaneeth, Yeah,thanks my friend. I have solve this problem by checking the site you provide. Thank You so much for the information and advice share me. Have a wonderful day. Regards Drex ;)
Great ! glad to help.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hello all, I'm trying to create a user login verification for my Window Form Application using VB.NET 2003 connect with MySQL 5.0 database. When the login form load,I have load all the USERID,USERNAME and USERPASSWORD into a dataset and put into a datatable name"cashier" shown inside my code below:
ObjConn = New OdbcConnection(Connect())
ObjComm = New OdbcCommand("SELECT * FROM pos_cashier WHERE LocationCode='" & TerminalLocate & "'", ObjConn)ObjConn.Open()
ObjAdapter.SelectCommand = ObjComm
ObjAdapter.Fill(DS, "cashier")
DT = DS.Tables("cashier")
ObjConn.Close()Now I need someone can guide me how to select a row or column inside this datatable so I can check the user login name and password are same with what inside this cashier datatable which used to authorise user login. What I wish to do is something as follow: If textbox1.text = datatable.cashier.USERNAME Then If textbox2.text = datatable.cashier.USERPASSWORD Then UserloginSuccess = True Dim MainForm as new MainForm Me.Hide() MainForm.Show() Else Messagebox.show("Sorry,Wrong Password") End If Else Messagebox.Show("Sorry,Username not available on the system.") End IF Anyone can give me some help about selecting this datatable? Thank you for reading. Regards Drex
IMO, you should try to select the user from table with the name and password without loading everybody into the dataset, ie Select * from pos_cashier Where LocationCode = @loc And UserName = @name And UserPassword = @password If you get a row, the password is valid, otherwise invalid.