这让我抓狂 ;)
我有这个存储过程...
ALTER PROCEDURE [dbo].[sproc_FindFoundries]
(@materials varchar(1000),
@capabilities varchar(1000))
AS
BEGIN
/* insert SQL code here */
END
该过程接受两个逗号分隔的字符串。在我的应用程序中,我有以下代码。
BCDataContext db = new BCDataContext();
SqlParameter prmMaterials = new SqlParameter("materials", SqlDbType.VarChar, 1000);
prmMaterials.Value = materialList;
SqlParameter prmCapability = new SqlParameter("capabilities", SqlDbType.VarChar, 1000);
prmCapability.Value = capabilityList;
SqlConnection cn = new SqlConnection(db.Connection.ConnectionString);
SqlCommand cmd = new SqlCommand("sproc_FindFoundries", cn);
cmd.Parameters.Add(prmMaterials);
cmd.Parameters.Add(prmCapability);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
当我执行代码时,出现错误
Procedure or function [sproc_name] expects parameter '@materials', which was not supplied.
当我尝试填充数据集时。测试时,我已验证两个参数都包含数据并且不为空。我错过了什么吗?将不胜感激第二双眼睛。
谢谢。
使用@materials
, @capabilities
作为参数名:
using (BCDataContext db = new BCDataContext())
using (SqlConnection connection = new SqlConnection(db.Connection.ConnectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "sproc_FindFoundries";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@materials", SqlDbType.VarChar, 1000).Value = materialList;
command.Parameters.Add("@capabilities", SqlDbType.VarChar, 1000).Value = capabilityList;
DataSet ds = new DataSet();
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
da.Fill(ds);
}
}
我是一名优秀的程序员,十分优秀!