How to execute a stored procedure within C# program

前端 未结 13 1685
别跟我提以往
别跟我提以往 2020-11-22 00:10

I want to execute this stored procedure from a C# program.

I have written the following stored procedure in a SqlServer query window and saved it as stored1:

<
13条回答
  •  臣服心动
    2020-11-22 00:30

    using (SqlConnection sqlConnection1 = new SqlConnection("Your Connection String")) {
    using (SqlCommand cmd = new SqlCommand()) {
      Int32 rowsAffected;
    
      cmd.CommandText = "StoredProcedureName";
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Connection = sqlConnection1;
    
      sqlConnection1.Open();
    
      rowsAffected = cmd.ExecuteNonQuery();
    
    }}
    

提交回复
热议问题