I have tried many different things but at this point I am stumped.
Public Function GetCust(email As String) As Integer Dim cs As String = <connection string> Dim conn As New MySqlConnection(cs) Dim custId As Integer Dim cust_query As String = "SELECT entity_id FROM customer_entity WHERE email = '@email'" Dim com As New MySqlCommand(cust_query, conn) Dim reader As MySqlDataReader Try conn.Open() com.Parameters.Add("@email", MySqlDbType.String) com.Parameters("@email").Value = email reader = com.ExecuteReader While reader.Read() custId = reader.GetInt16(0) End While MsgBox(custId) Catch ex As Exception MsgBox(ex.ToString) End Try Return custId End Function
It should be pulling only one column and one row from a table so i should only have one value out of the query but it isn't entering the loop. Seems like its a syntax error on my part but can't seem to find it. Thanks in advance!Answer1:
You should remove the quotes around the email parameter in the SQL string:
Dim cust_query As String = "SELECT entity_id FROM customer_entity WHERE email = @email"
This will generate SQL that looks like
WHERE email = ''firstname.lastname@example.org''
when it should be
WHERE email = 'email@example.com'