Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,583 members, 7,955,145 topics. Date: Saturday, 21 September 2024 at 05:54 PM |
Nairaland Forum / Science/Technology / Programming / Sql "Select" With Vb.net (1526 Views)
Android Application With Vb.net / Compute CGPA With Vb.net / Post Ur Vb 6.0 Questions Here (2) (3) (4)
Sql "Select" With Vb.net by jboy01(m): 11:29am On Jul 18, 2013 |
pls pals, i am working on an e-votting application, but am getting a runtime error in my code. the code is to compare the login password entered by the volter to the one on the database table. this is my code. Private Sub passbox_keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) ' CType(sender textbox).text If e.KeyCode = Keys.Enter Then Dim SqLConnection As MySqlConnection = New MySqlConnection() Dim sqlcommand As New MySqlCommand Dim connectionString As String = "Server=localhost; port=3306; User Id=root; Password=jboy;Database=fut_votting" SqLConnection.ConnectionString = connectionString ' Using SQLConnection As New MySqlConnection(connectionString) With sqlcommand .CommandText = "SELECT names FROM student_data WHERE id=1 and password='" & passbox.Text & "'" End With Dim reder As MySqlDataReader = sqlcommand.ExecuteReader() While reder.Read() Dim mainform As New mainForm mainform.Show() Me.Dispose() End While ' End Using Try SqLConnection.Open() sqlcommand.ExecuteNonQuery() Catch ex As MySqlException MsgBox(ex.Message.ToString) Finally SqLConnection.Close() End Try End If End Sub but am getting a runtime error on the Dim reder As MySqlDataReader = sqlcommand.ExecuteReader(). what doo you think the problem is. pls i need reply urgently. thanks |
Re: Sql "Select" With Vb.net by Nov1ce(m): 5:58pm On Jul 18, 2013 |
Try using this instead "Using reader As MySqlDataReader = command.ExecuteReader" |
Re: Sql "Select" With Vb.net by jboy01(m): 8:13am On Jul 23, 2013 |
⌣»̶·̵̭̌·̵̭̌✽̤̈̊Ŧђɑ̤̥̈̊п̥̥̲̣̣̣kƨ̣̣̣̇̇̇̇✽̤̈̊·̵̭̌·̵̭̌«̶⌣ |
Re: Sql "Select" With Vb.net by uken73(m): 6:54pm On Jul 23, 2013 |
Your implementation approach does not seem to be the best. You are using a keydown event to handle the authentication. This will make the system to watch every key type event when you don't need those events. That is not efficient. A better approach will be to have a button maybe named login or connect and implement your authentication/database verification on the button click event. That could be something like; Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click Dim SqLConnection As MySqlConnection Try SqlConnection = New MySqlConnection() Dim sqlcommand As New MySqlCommand Dim connectionString As String = "Server=localhost; port=3306; User Id=root; Password=jboy;Database=fut_votting" SqlConnection.ConnectionString = connectionString With sqlcommand .CommandText = "SELECT names FROM student_data WHERE id=1 and password='" & passbox.Text & "'" End With SqlConnection.Open() Dim reder As MySqlDataReader = sqlcommand.ExecuteReader() Dim reader As SqlDataReader If reder.Read() Then Dim mainform As New mainForm mainform.Show() Me.Dispose() End If ' End Using 'sqlcommand.ExecuteNonQuery() ----Should not be necessary. 'Typically used if you are executing and update/delete statement Catch ex As MySqlException MsgBox(ex.Message.ToString) Finally SqlConnection.Close() End Try End Sub Please Note: I usually program for a MS SQL Server database. I don't have the library for MySQL Server connection, hence, I havn't tested the above code. However, with my experience with the MS SQL Server library, there were some issues with your arrangements. For instance the point "Dim reder As MySqlDataReader = sqlcommand.ExecuteReader()" where you have the error message is comming before "SqLConnection.Open()" which opens a connection to the database. That should be the source of the error, and that line of code was not in your error handler section. The line "sqlcommand.ExecuteNonQuery()" is not necessary. "sqlcommand.ExecuteReader()" is similar statement to "sqlcommand.ExecuteNonQuery()", difference being that the former is used for a database query while the later is used for data update,insert or delete. I hope that helps. |
Re: Sql "Select" With Vb.net by jboy01(m): 9:56pm On Jul 23, 2013 |
thank you very much |
Re: Sql "Select" With Vb.net by uken73(m): 11:33am On Jul 26, 2013 |
jboy01: thank you very much jboy, I think you should state if your problem has been solved so that no one bothers to reply to this post anymore. |
Re: Sql "Select" With Vb.net by jboy01(m): 9:43am On Jul 28, 2013 |
ok the problem has been solved 1 Like |
(1) (Reply)
I Will Implement Voguepay Payment For Your Android App / Android Learning Community (ALC) By Andela / Learn & Master Electronics Design And Embedded Systems!
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 16 |