过程或函数需要未提供的参数

时间:2021-02-09 01:51:16

Driving me mad on a personal project; I know I've done this before but elsewhere and don't have the code. As far as I can see, I'm setting the parameter, I'm setting its value, the connection is open, yet when I try to fill the dataset I get the error 'Procedure or function expects parameter "@test" which was not supplied'.

在个人项目上让我抓狂;我知道我以前也做过,但是别的地方没有代码。就我所见,我在设置参数,我在设置它的值,连接是打开的,但是当我试图填充数据集时,我得到了错误的过程或函数期望参数“@test”,但没有提供它。

(This is obviously a simplified test! Same error on this or the real, rather longer code though.)

这显然是一个简化的测试!同样的错误或者是真实的,更长的代码)

C#:

c#:

SqlCommand l_oCmd;
DataSet l_oPage = new DataSet();

l_oCmd = new SqlCommand("usp_test", g_oConn);
l_oCmd.Parameters.Add(new SqlParameter("@test", SqlDbType.NVarChar));
l_oCmd.Parameters[0].Value = "hello world";

SqlDataAdapter da = new SqlDataAdapter(l_oCmd);
da.Fill(l_oPage);

SQL:

SQL:

create procedure usp_test
(
    @test nvarchar(1000)
)
as
select @test

What have I missed?

我错过了什么?

1 个解决方案

#1


39  

Change the command type to Procedure

将命令类型更改为过程。

#1


39  

Change the command type to Procedure

将命令类型更改为过程。