【发布时间】:2013-02-19 18:48:26
【问题描述】:
我有一个这样调用的存储过程:
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();
}
【问题讨论】:
-
您使用的是哪个数据库接口? OleDb 喜欢以 @ 开头的参数,但 SqlDb 更喜欢像 ? 这样的占位符。另外,您是否尝试过使用“exec SpCreate '00111', @myId”?
标签: .net sql stored-procedures sqlparameter