码迷,mamicode.com
首页 > 数据库 > 详细

连接SQL Server执行SQL语句

时间:2014-06-05 17:20:30      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:c   a   get   com   string   art   

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

连接SQL Server执行SQL语句

标签:c   a   get   com   string   art   

原文地址:http://www.cnblogs.com/fourw/p/3768602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!