Click here to Skip to main content
15,125,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,
Can i bind data grid view with sql procedure in my procedure i want to use only cursor
on any table...
how to use please....
thanks in advance
Posted

1 solution

for more detail on your procedure writing please refer this link
Sql Server - How to write a Stored procedure in Sql server[^]

and you can simply call your procedure using this type c# code.
//C#
C#
try
  {
     sqlConnection = new SqlConnection(dbConnectionString);
     SqlCommand command = new SqlCommand("Your procedure name", sqlConnection);
     command.CommandType = CommandType.StoredProcedure;
     /* If your procedure acepting parameter then pass parameter value like this...
      also you need to pass proper data type here i use 'SqlDbType.VarChar', but you need to modify based on your parameter type.
*/
     command.Parameters.Add("@PARAMNAME1", SqlDbType.VarChar).Value = "YOUR VALUE" //like this  txtFirstName.Text;
     command.Parameters.Add("@PARAMNAME2", SqlDbType.VarChar).Value = "YOUR VALUE" //like this  txtLastName.Text;
/* now all set, so open your database connection and execute your command over database */
     sqlConnection.Open();
     return command.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }


or for more detail on this please refer this link...

Create CLR Stored Procedure with Visual Studio Express Edition[^]
   
v2
Comments
9783444184 16-Oct-12 0:27am
   
how to bind in data grid view if i am using cursor in my procedure.
Tejas Vaishnav 17-Oct-12 3:59am
   
cursor will return row then your procedure will also return that data, so you can directly use that data to fill your data table or data set to bind with your grid.

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