当我想在C#应用程序中执行我的SQL语句时出现错误,它是:
没有给出一个或多个必需参数的值。
我正在使用带有MS访问数据库的c#。 这是我的代码:
string string2 = "";
if (radButton2 != null)
{
string2 = " and signaal1.info='" + radButton2.Text + "' ";
}
else
string2 = " and signaal1.info='0' ";
if (radButton3 != null)
{
string2 += " and situation.info='" + radButton3.Text + "' ";
}
OleDbCommand cmd = new OleDbCommand("SELECT actionz.info, relationz.id AS actionz FROM ((((relationz LEFT OUTER JOIN conditions ON relationz.conditions_id = conditions.id) LEFT OUTER JOIN situation ON relationz.situation_id = situation.id) LEFT OUTER JOIN car_type ON relationz.car_id = car_type.id) LEFT OUTER JOIN actionz ON relationz.action_id = actionz.id) LEFT OUTER JOIN signal AS signaal1 ON relationz.signal_id = signaal1.id where car_type.info='" + radButton1.Text + "' " + string2 + " ORDER BY conditions.id ASC", objConn);
//cmd.Parameters.AddWithValue("@car_type", radButton1.Text);
OleDbDataReader dataReader = cmd.ExecuteReader();
答案 0 :(得分:0)
错字:
" ...info='" + radButton1.Text + "' " + string2 + " ORDER BY ..."
应该是
" ...info='" + radButton1.Text + string2 + "' ORDER BY ..."
或者如果您需要值之间的空格:
" ...info='" + radButton1.Text + " " + string2 + "' ORDER BY ..."
如上所述,开放注射。