C#2.0:调用存储过程 [转]
做项目的时候用到了,.NET1.1和2.0版本的使用方法也略有不同,记在这里。
string ConnStr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(ConnStr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "[EachRows_M]";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@ETIME", SqlDbType.VarChar, 3);
cmd.Parameters["@ETIME"].Value = ETIME;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet MyDs = new DataSet();
adapter.Fill(MyDs);
conn.Close();
SqlConnection conn = new SqlConnection(ConnStr);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
cmd.CommandText = "[EachRows_M]";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@ETIME", SqlDbType.VarChar, 3);
cmd.Parameters["@ETIME"].Value = ETIME;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet MyDs = new DataSet();
adapter.Fill(MyDs);
conn.Close();