不带参数的存储过程:
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand(Procedure_name, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Close();
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
带参数的存储过程的调用:
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
SqlCommand cmd = new SqlCommand(Procedure_name, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter pare1 = new SqlParameter("@id", SqlDbType.VarChar, 50);
SqlParameter pare2 = new SqlParameter("@name", SqlDbType.VarChar, 50);
cmd.Parameters.Add(pare1);
cmd.Parameters.Add(pare2);
cmd.Parameters["@id"].Value = parm1;
cmd.Parameters["@name"].Value = parm2;
SqlDataAdapter da = new SqlDataAdapter(cmd);
conn.Close();
DataSet ds = new DataSet();
da.Fill(ds);
return ds;