Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27214

MySQL Server Query help

$
0
0
Was hoping that someone could look at this code and hopefully help me understand where my problem is. I'm trying to query a MySQL database with the following code:
queryString(0) = "SELECT calF_Low1, calF_Low2, calF_Mid1, calF_Mid2, calF_High1, calF_High2 FROM [fbTestResults].[testMain] WHERE serialNumber = @serialNumber"

Dim conn As New MySqlConnection
Dim query As New MySqlCommand(queryString(i))
query.Parameters.AddWithValue("@serialNumber", SerialBox.Text)
Dim queryResult(i) As String
conn.ConnectionString = "Server = ****; Uid= ***; Pwd = *******; port = 3306; Database = fbTestResults"

Try
conn.Open()
'For i = 0 To 5
i = 0
queryResult(0) = query.ExecuteScalar().ToString


MsgBox(queryResult(0))


'Next
Return
Catch ex As MySqlException
MsgBox("No connection to calibration database")


End Try



I feel like my code is connecting to the server, as I'm not getting a MySqlException (which would happen every time the connection string was incorrect), but nonetheless the code breaks on the queryExecuteScalar() line and throws a System.InvalidOperationException with additional information saying that the connection must be valid and open. Any idea why this would be happening?

I know my code is probably pretty messy too. To clarify, the end result is for the all of the selected values to go into a string array, but right now i'm just trying to get any query to run.
Tanks!

Viewing all articles
Browse latest Browse all 27214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>