我在调用下面的代码。C#,sp_executesql和语法错误
上线(IDataReader dr = cmd.ExecuteReader())带有的sql barfs'CompanyUpdate'附近的语法不正确。
using (SqlCommand cmd = new SqlCommand("CompanyUpdate"))
{
cmd.Parameters.Add("@CompanyID",SqlDbType.Int);
cmd.Parameters.Add("@Description",SqlDbType.VarChar,50);
cmd.Parameters["@CompanyID"].Value = companyid;
cmd.Parameters["@Description"].Value = description;
SqlConnection cn = new SqlConnection("Data Source=[datasource];Initial Catalog=dotNext;User ID=[user];Password=[password];Pooling=True;Application Name=dotNext");
cn.Open();
cmd.Connection = cn;
using (IDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
this.CompanyID = dr.GetInt32(0);
}
}
}
我看了一下sqlprofiler,注意到以下几点:
exec sp_executesql N'CompanyUpdate',N'@CompanyID int,@Description varchar(50)',@CompanyID=56,@Description='APC'
包装纸我的指挥机智sp_executesql的。我所有的其他sql命令都是在没有问题的情况下执行的。
所以我的问题是两个: 1.为什么它使用sp_executesql? 2.我做错了什么?
详细信息:SQL2005,C#,VS2005
这太恼人了!谢谢! – 2008-12-18 05:16:16