我尝试了很多不同的东西,但在这一点上我很难过。
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
它应该只从表中提取一列和一行,所以我应该只有一个值来自查询,但它没有进入循环。对我来说似乎是语法错误,但似乎找不到。提前致谢!