private static readonly string connString = ConfigurationManager.ConnectionStrings["WebContext"].ConnectionString;
public static int ExecuteNonQuery(string sql,CommandType type, params SqlParameter[] Parameter)
{//先创建链接 传入从 web.config里面获取到的链接语句
using (SqlConnection conn=new SqlConnection (connString)) {
//打开链接
conn.Open();
//再传入SQL语句和参数 传入俩个参数: 1 一个sql语句 2打开连接的参数
using (SqlCommand cmd=new SqlCommand (sql,conn))
{
//这是可以执行存储过程和不执行存储过程的做法
不执行存储过程为 type=CommandType.Text ,
执行存储过程为: type=CommandType.StoredProcedure