过程或函数 [sproc_name] 需要参数“@materials”,但未提供该参数

发布于 2024-10-15 20:11:18 字数 1035 浏览 4 评论 0原文

这让我发疯;)

我有这个存储过程...

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);

当我执行代码时,出现错误

过程或函数 [sproc_name] 需要参数“@materials”,但未提供该参数。

当我尝试填充数据集时。测试时我已验证这两个参数都包含数据且不为空。有什么我错过的吗?如果有第二双眼睛,我们将不胜感激。

谢谢。

This is driving me nuts ;)

I have this stored procedure ...

ALTER PROCEDURE [dbo].[sproc_FindFoundries] 
    (@materials varchar(1000),
     @capabilities varchar(1000))
AS
BEGIN

 /* insert SQL code here */

END

The procedure accepts two comma delimited strings. In my application I have the following code.

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);

When I execute the code, I get the error

Procedure or function [sproc_name] expects parameter '@materials', which was not supplied.

when I try fill the dataset. When testing I have verified that both parameters contain data and are not null. Is there something I've missed? A second pair of eyes would be greatly appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌上芳菲 2024-10-22 20:11:18

使用@materials@capability作为参数名称:

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);
    }
}

Use @materials, @capabilities as parameters' name:

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);
    }
}
凶凌 2024-10-22 20:11:18

命名参数时需要添加@

SqlParameter prmMaterials = new SqlParameter("@materials", SqlDbType.VarChar, 1000)

When naming your parameters you need to put the @ in

SqlParameter prmMaterials = new SqlParameter("@materials", SqlDbType.VarChar, 1000)
萌辣 2024-10-22 20:11:18

您将参数称为“材料”和“功能”,而不是“@材料”和“@功能”

You are calling your parameters "materials" and "capabilities" instead of "@materials" and "@capabilities"

樱&纷飞 2024-10-22 20:11:18

我这样尝试,它对我有用:

int deal_id = 25;
_dbContext.Database.ExecuteSqlCommand("exec sp_getdeal @deal_id={0}", deal_id);

我的程序是这样的:

ALTER PROCEDURE [dbo].[sp_getdeal]
(
    @deal_id INTEGER
)
AS
BEGIN

I tried like this, Its worked for me:

int deal_id = 25;
_dbContext.Database.ExecuteSqlCommand("exec sp_getdeal @deal_id={0}", deal_id);

My procedure is like this:

ALTER PROCEDURE [dbo].[sp_getdeal]
(
    @deal_id INTEGER
)
AS
BEGIN
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文