'?'附近语法错误!!!!!!!!!!!!(在线等)。
using (SqlConnection connection = new SqlConnection(_ConnectionString))
{
using (SqlCommand command = new SqlCommand( " ", connection))
{
string sql = "select * from t1 where f1=? ";
command.Parameters.Add( "@f1 ", SqlDbType.VarChar,255).Value = "/ ";
command.CommandText = sql;
connection.Open();
command.ExecuteReader();
connection.Close();
}
}
--------------------------------------
'? ' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: '? ' 附近有语法错误。
源错误:
行 69: command.CommandText = sql;
行 70: connection.Open();
行 71: command.ExecuteReader();
行 72: connection.Close();
行 73: }
------解决方案--------------------using (SqlConnection connection = new SqlConnection(_ConnectionString))
{
using (SqlCommand command = new SqlCommand( " ", connection))
{
string sql = "select * from t1 where f1=@f1 "; //与后面添加的参数名一样
command.Parameters.Add( "@f1 ", SqlDbType.VarChar,255).Value = "/ ";
command.CommandText = sql;
connection.Open();
command.ExecuteReader();
connection.Close();
}
}