public static DataTable GetData()
{
string Connect
= ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection sc = new SqlConnection(Connect);
sc.Open();
SqlCommand cm = new SqlCommand("select * from Department");
cm.Connection = sc;
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cm);
sda.Fill(ds,
"abc");
DataTable dt = ds.Tables["abc"];
return
dt;
}
public static string ExecSQL(string sql)
{
string Connect =
ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection sc = new SqlConnection(Connect);
sc.Open();
SqlCommand cm = new SqlCommand(sql);
cm.Connection =
sc;
string str = cm.ExecuteNonQuery().ToString();
sc.Close();
return str;
}
连接SQL Server执行SQL语句,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/fourw/p/3768602.html