我有一个像这样调用的存储过程:
string proc = "SpCreate '00111', 3";
using (SqlCommand command = new SqlCommand(proc, conn))
{
command.CommandType = CommandType.Text;
command.CommandTimeout = 1000;
string returnCode = command.ExecuteScalar().ToString();
}
上面的神工作正常。但是一旦我添加了一个参数,我就会在“SpCreate”附近得到不正确的语法。是什么赋予了?(下面的代码会导致错误。)
string proc = "SpCreate '00111', @myId";
using (SqlCommand command = new SqlCommand(proc, conn))
{
SqlParameter paramName = new SqlParameter("@myId", SqlDbType.Int) { Value = 3 };
command.Parameters.Add(paramName);
command.CommandType = CommandType.Text;
command.CommandTimeout = 1000;
string returnCode = command.ExecuteScalar().ToString();
}