One-layer call
One-tier Sqlconnction connection database
Two-tier SqlCommand Execute SQL statement
Three-layer SqlDataAdapter fills a dataset or dataset
Four-layer dataset This is a collection of tables. The DataTable is one of his tables,
Five-tier DataTable
Six-layer DataRow DataColumn
SqlCommandBuilder for generating SQL statements to update the database
Cases:
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 ")//can directly avoid SqlCommand directly with SqlDataAdapter
*/
/*
SqlDataAdapter adapter = new SqlDataAdapter ("select *", Conn);
*/
/*
SqlDataAdapter adapter = new SqlDataAdapter (cmd);
*/
SqlDataAdapter adapter = new SqlDataAdapter ();
Adapter. Selectcommand=cmd;
SqlCommandBuilder builder = new SqlCommandBuilder (adapter);//Add this phrase before updating the database
DataSet ds = new DataSet ();
Adapter. Fill (ds, "Titles");
C # connecting SQL Server database