【发布时间】:2018-07-26 11:09:24
【问题描述】:
如果我在我的服务器上执行它并使用我的参数构建一个执行语句(例如 string sql = "Exec Get_Data '" + St + " ' ..." . 但是,一旦我尝试:
string strQS = "Exec Get_Data @param1,@param2,@param3,@param4..."
using (SqlConnection conSQL = new SqlConnection(connectionString))
{
using (SqlCommand cmdSQL = new SqlCommand(strQS, conSQL))
{
conSQL.Open();
cmdSQL.Parameters.AddWithValue("@param1", SqlDbType.VarChar).Value = St;
cmdSQL.Parameters.AddWithValue("@param2", SqlDbType.VarChar).Value = Loc;
...
我收到以下错误:
列名或提供的值的数量与表定义不匹配。
显然,如果我可以在使用参数化查询之前运行它,我的列名没有任何问题,但我的值如何被处理。我所有的变量都是字符串类型,SQL Server 期望所有参数都是varchar...有什么想法吗?
【问题讨论】:
-
显示整个代码。您是否将命令类型设置为存储过程?您在其他参数名称中有错字吗?我们所能做的就是用您向我们展示的有限数量进行猜测。请提供minimal reproducible example。
标签: c# sql-server