我正在尝试使用 C# 连接到我的数据库并查询一些数据。
但是尝试连接时出现此错误:
{"Fatal error encountered during command execution."}
{"Parameter '?param1' must be defined."}
代码:
checkmsisdn.CommandText = "SELECT name FROM acl where msisdn = ?param1 and passwd = ?param2 and items LIKE (\"%?param3%\")"; //fourth
//try
//{
sqlConn.Open();
Reader = checkmsisdn.ExecuteReader();
checkmsisdn.Parameters.Add(new MySqlParameter("param1", msisdn));
checkmsisdn.Parameters.Add(new MySqlParameter("param2", passwd));
checkmsisdn.Parameters.Add(new MySqlParameter("param3", itemno));
//}
//catch
//{
// Console.WriteLine("Error Connecting to Database\n");
//}
while (Reader.Read())
{
name = (Reader.GetValue(0).ToString());
}
查询将只返回一行,即名称。我是否为此查询正确使用了参数?