Refer the below code to call and pass parameter to a MS SQL Server Stored procedure. Replace the YOUR CONNECTION STRING text with the connection string of your database.
Here UpdateIssueStatus_SP is the Stored Procedure name.
- SqlParameter param;
- SqlCommand cmd;
- string connStr = "YOUR CONNECTION STRING";
- public void UpdateIssueStatus(int issueNo, char status)
- {
- try
- {
- SqlConnection conn = new SqlConnection(connStr);
- conn.Open();
- cmd = new SqlCommand("UpdateIssueStatus_SP", conn);
- cmd.CommandType = System.Data.CommandType.StoredProcedure;
- param = new SqlParameter("@IssueNo", SqlDbType.Int);
- param.Direction = ParameterDirection.Input;
- param.Value = issueNo;
- cmd.Parameters.Add(param);
- param = new SqlParameter("@ApprovalStatus", SqlDbType.Char);
- param.Direction = ParameterDirection.Input;
- param.Value = status;
- cmd.Parameters.Add(param);
- cmd.ExecuteNonQuery();
- conn.Close();
- }
- catch (Exception ex)
- {
- }
- }
No comments:
Post a Comment