直奔主题,记录
class="brush:csharp;gutter:true;"> using (SqlConnection connection = new SqlConnection(SqlServerHelper.ConnectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand("存储过程名", connection); cmd.Parameters.Add("@param1", SqlDbType.Int); cmd.Parameters["@param1"].Value = "param1_value"; cmd.Parameters["@param1"].Direction = ParameterDirection.Input; cmd.Parameters.Add("@param2", SqlDbType.Int); cmd.Parameters["@param2"].Value = "param2_value"; cmd.Parameters["@param2"].Direction = ParameterDirection.Input;//Outpu cmd.Connection = connection; cmd.CommandType = CommandType.StoredProcedure;//这里标识调用类型 SqlDataReader dr = cmd.ExecuteReader(); //执行SQL语句,返回结果集合 //int rerows = cmd.ExecuteNonQuery();//执行SQL语句,受影响的行数 while (dr.Read()) { //返回结果处理 //dr[0],dr["col_name"] } dr.Close(); //关闭执行 connection.Close(); //关闭数据库 }