我有这个代码的和平,我需要从Mysql
检索数据。如果我使用参数化查询,它不会取实际的参数值,而是将参数名称作为值。C#mysql参数化查询
Error: @choise must be defined
MySqlConnection connection = new MySqlConnection("");
MySqlDataAdapter mySqlDataAdapter;
DataSet DS;
private string columnValue = xxx;
private string Choise = yyy;
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM table2 WHERE " + columnValue + " = @choise";
command.Parameters.Add(new MySqlParameter("@choise", Choise));
DS = new DataSet();
connection.Open();
mySqlDataAdapter = new MySqlDataAdapter(command.CommandText, connection);
mySqlDataAdapter.Fill(DS);
connection.Close();
当我运行此我得到的查询,如:
SELECT * FROM table2 WHERE xxx = @choise
,而不是
SELECT * FROM table2 WHERE xxx = yyy
。 问题在哪里?
我曾尝试: command.Parameters.Add(new MySqlParameter("@choise", Choise));
command.Parameters.AddWithValue("@choise", Choise);
它,当我使用实际变量而不是参数正常工作。
没了,同样的问题... –
当我得到致命错误例外它说:“参数@choise必须定义”,这是显而易见的,它已被定义... –