标签:
一层一层的调用
一层SqlConnction连接数据库
二层SqlCommand执行SQL语句
三层SqlDataAdapter填充DataSet或者DataSet
四层DataSet 这是一个表的集合DataTable是他的一个表,
五层DataTable
六层DataRow DataColumn
SqlCommandBuilder用于生成SQl语句更新数据库
例:
SqlConnection conn=new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog = EmployeeDB; Integrated Security=True");
SqlCommand cmd=new SqlCommand("select *",conn);
/*
SqlCommand cmd=new SqlCommand(conn);
cmd.Connection=conn;
*/
/*
SqlCommand cmd=new SqlCommand();
cmd.Connection=conn;
cmd.CommandText="select *";
*/
/*
SqlDataAdapter adapter = new SqlDataAdapter("select *", “Data Source=.\\SQLEXPRESS;Initial Catalog = EmployeeDB; Integrated Security=True”);//可以直接避开SqlCommand直接用SqlDataAdapter
*/
/*
SqlDataAdapter adapter = new SqlDataAdapter("select *", Conn);
*/
/*
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
*/
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand=cmd;
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);//加上这一句话,在更新数据库之前
DataSet ds = new DataSet();
adapter.Fill(ds, "Titles");
标签:
原文地址:http://www.cnblogs.com/beige1315402725/p/4918778.html