Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

C# code behind - how do you call a Stored Procedure?

In C#, how do you create parameters and call a Stored Procedure?

Resource_Add 'eric','eric bills','eric@uwinfinancial.com',1

ALTER PROCEDURE [dbo].[Resource_Add]
      @ResourceName      nvarchar(64),      -- name of the resource
      @ResourceDesc      ntext,            -- optional description of the resource
      @ResourceEmail      nvarchar(64),      -- optional e-mail contact information
      @EnableEmailReminders int      -- indicates preference to receive reminder
                              -- notification by e-mail (REN only)

...
...
SOLUTION
Avatar of Raju Srivatsavaye
Raju Srivatsavaye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Knowlton

ASKER

Here was what I ended-up using -- seems to work okay:


string fullConnString = CommonFunctions.ReturnConnectionStringGivenNameInWebConfig(CommonFunctions.UwinWebSchedule2DBConnString);

        SqlConnection sqlconn = new SqlConnection(fullConnString);
        sqlconn.Open();

        SqlCommand sqlcomm = new SqlCommand("Resource_Add", sqlconn);
        sqlcomm.CommandType = CommandType.StoredProcedure;

        SqlParameter sqlparameter = new SqlParameter("@ResourceName", username.Text);
        SqlParameter sqlparameter2 = new SqlParameter("@ResourceDesc", "bills");
        SqlParameter sqlparameter3 = new SqlParameter("@ResourceEmail", email.Text);
        SqlParameter sqlparameter4 = new SqlParameter("@EnableEmailReminders", 1);
        //sqlparameter2.Direction = ParameterDirection.Output

        sqlcomm.Parameters.Add(sqlparameter);
        sqlcomm.Parameters.Add(sqlparameter2);
        sqlcomm.Parameters.Add(sqlparameter3);
        sqlcomm.Parameters.Add(sqlparameter4);

        sqlcomm.ExecuteNonQuery();