连接SQL Server执行SQL语句

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;
}

上一篇:安装 android x86 到 virtual box


下一篇:Android中关于ListView的使用(上)ArrayAdapter