Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created one procedure in sql server with cursor varying output parameter
how to access this procedure from asp.net page and bind data to gridview

ex:
create proc sp_getdata @mycur cursor varying output
as
begin
set @mycur=cursor static for select * from emp
open @mycur
end

execution:
declare @mydatacur cursor
exec sp_jemp_getdata @mycur=@mydatacur output
fetch next from @mydatacur
while @@fetch_status=0
begin
fetch next from @mydatacur
end
Posted
Updated 13-Jul-10 0:39am
v5

That's not really how you're supposed to use cursors. I'm not sure this can even work. You should write a proc that uses the cursor to fill a table.
 
Share this answer
 
Try the below code to call your SP. Then you can easily bind the result set to your gridview. Just do a gv.DataSource = DataSet and then gv.Bind()

SqlConnection lSQLConn = null;
SqlCommand lSQLCmd = new SqlCommand();
//Declare a DataAdapter and a DataSet
SqlDataAdapter lDA = new SqlDataAdapter();
DataSet lDS = new DataSet();
 
//...Execution section
 
// create and open a connection object
lSQLConn = new SqlConnection(connStr);
lSQLConn.Open();
//The CommandType must be StoredProcedure if we are using an ExecuteScalar
lSQLCmd.CommandType = CommandType.StoredProcedure;
lSQLCmd.CommandText = "sp_YourSPName"; 
lSQLCmd.Parameters.Add(new SqlParameter("@Parm1", aParm1));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm2", aParm2));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm3", aParm3));
lSQLCmd.Parameters.Add(new SqlParameter("@Parm4", aParm4));
 
lSQLCmd.Connection = lSQLConn;
//Fill the DataAdapter with a SelectCommand
lDA.SelectCommand = lSQLCmd;
lDA.Fill(lDS);


To see a full explanation go to:
Executing a Stored Procedure from a WCF Service Method C#
 
Share this answer
 
Comments
fjdiewornncalwe 19-Oct-11 13:47pm    
This question is already well over 1 year old. Please don't answer questions that are that old already, even if they don't have a solution marked on them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900