63954

MySQL Data Reader not entering the loop

Question:

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 = ''myemail@mydomain.com''

when it should be

WHERE email = 'myemail@mydomain.com'

Recommend

  • Update Column If count(id) have more than one in table
  • SQL Query Advice - Most recent item
  • getting error incorrect syntax near the keyword as in sql server
  • update oracle statement doesn't work
  • MySQL Data Reader not entering the loop
  • How i can read an Object within ionic 2 and angular 2?
  • Why cart is empty after add product
  • Unable to cast object of type 'System.Data.SqlClient.SqlDataReader' to type 'System.I
  • UseDatabaseNullSemantics still generating NULL checks
  • Checking if another web server is listening from asp
  • Open two windows onClick button javascript [duplicate]
  • How can I merge 2 rows in an innodb table
  • PHP Statement Should return Multiple objects but only returns one
  • SQL Query - Select Query
  • Dapper or MySql not finding stored procedures that contain a full stop “.”
  • ASP.Net C# - MySQLTransaction multiple inserts
  • Automatic generation of record type based on MySql database tables, for use in FSharpDAL
  • Magento - Load Product Collection with Pagination
  • AES128 bit encryption string is not similar as on .net
  • Two values inside a combobox in vb
  • VB.NET connection must be valid and open ERROR
  • Insert multiple object to MySQL
  • Check if MySqlConnection is using SSL
  • Runs as a macro on visual basic for windows application - Access Database
  • How to perform join operation similar to SQL join in Azure DocumentDB
  • query relation table against another column
  • Getting the id of the last inserted record from an MSSQL table using PDO and PHP
  • Asp calendar with datasource repeats the label
  • MySQL Connection will not close
  • Why does opening a connection throw a distributed transactions error in MySQL? (.NET Connector)
  • Display Images one by one with next and previous functionality
  • ORA-29908: missing primary invocation for ancillary operator
  • How to get next/previous record number?
  • How do you join a server to an Active Directory (domain)?
  • How does Linux kernel interrupt the application?