过程或函数需要参数,但未提供. [英] Procedure or function expects parameter, which was not supplied.
问题描述
我在sql server中有此存储过程
I have this stored procedure in sql server
ALTER proc [dbo].[DataDetails3_proc]
@PageNum int OUTPUT
as
set nocount on
DECLARE @PageSize INT --How many rows to appear per page
--DECLARE @PageNum INT --What page number to appear
DECLARE @Skip INT --Working variable for where to start for page
DECLARE @SQL VARCHAR(8000) --Holds dynamic SQL
--===== Set the local variables for pagesize and page
-- PageSize and PageNum would be parameters in a stored proc
SET @PageSize = 50
--SET @PageNum = 0
SET @Skip = @PageSize*@PageNum
--===== Create the dynamic SQL statement that will produce the page
SET @SQL =
'
SELECT c.*
FROM dbo.DataDetails c,
(
SELECT TOP '+STR(@PageSize)+ ' *
FROM dbo.DataDetails WITH (NOLOCK)
WHERE ID NOT IN (SELECT TOP '+STR(@Skip)+' ID
FROM dbo.DataDetails
ORDER BY ID)
ORDER BY ID
) d
WHERE c.ID = d.ID
ORDER BY d.ID
'
--===== Produce the page
EXEC (@SQL)
运行良好,当我执行它时,它要求我放置参数PageNum并运行,现在我在winform应用程序中调用此过程,并说我必须传递参数,但我不知道我做错了什么,显然我在这里是代码.
Works fine, when I execute it it asks me to put parameter PageNum and it works, now I am calling this procedure in winform application and it says I have to pass parameter but I dont know what I am doing wrong, obviously I am, here is the code.
SqlDataAdapter daData = new SqlDataAdapter("DataDetails3_proc", cs);
daData.SelectCommand.CommandType = CommandType.StoredProcedure;
dsData.Clear();
daData.Fill(dsData, "DataDetails");
DataBS.DataSource = dsData.Tables[0];
daData.Dispose();
cs.Close();
dg.DataSource = DataBS;
SqlCommand command = new SqlCommand("DataDetails", cs);
SqlParameter param = new SqlParameter("@PageNum", SqlDbType.Int);
param.Direction = ParameterDirection.InputOutput;
param = new SqlParameter("@PageNum", page.Text);
页面是文本框,我在其中放置需要的参数
page is textbox in which I am putting that parameter I need
推荐答案
首先设置命令对象,并为其提供执行过程所需的一切.然后,将命令分配给DataAdapter并使用它来填充您的DataSet.
未经测试,但*应该*起作用!
Setup your command object first, giving it everything it needs to execute the procedure. Then, assign the command to the DataAdapter and use it to populate your DataSet .
Untested, but *should* work!
SqlCommand command = new SqlCommand("DataDetails3_proc", cs);
command.CommandType = CommandType.StoredProcedure;
SqlParameter param = new SqlParameter("@PageNum", SqlDbType.Int);
param.Direction = ParameterDirection.InputOutput;
param.Value = page.Text;
command.Parameters.Add(param);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataSet ds = new DataSet();
adapter.Fill(ds);
在这里查看更多信息...
http://csharp.net-informations.com/dataadapter/selectcommand-sqlserver.htm [ ^ ]
Have a look here for more info...
http://csharp.net-informations.com/dataadapter/selectcommand-sqlserver.htm[^]
这篇关于过程或函数需要参数,但未提供.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!