I have a SQL stored procedure that I need to run by pressing a button on a .Net form. I've created a SQLConnection, the form and a button, what code do I need to run the procedure.
I have a SQL stored procedure that I need to run by pressing a button
on a .Net form. I've created a SQLConnection, the form and a button,
what code do I need to run the procedure.
I remember first getting to grips with ADO.NET after using ADO and found it a nightmare so I thought I'd give you a couple of examples to get you going:
// This example populates a dataset with the results of the stored procedure
// i.e. an SP that returns recordsets.
SqlCommand _sqlcom = new SqlCommand("uspOrderRetrieval");
_sqlcom.CommandType = CommandType.StoredProcedure;
SqlDataAdapter _sqladp = new SqlDataAdapter();
// The following code adds a parameter to be used by the stored procedure
// if you have no parameters then obviously ignore it.
SqlParameter _sqlpar = new SqlParameter("@OrderID", SqlDbType.Int);
_sqlpar.Value = orderid;
_sqlcom.Parameters.Add(_sqlpar);
// end of parameter addition
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.