这两种连接有什么不同?
这两种连接有什么不同?
连接(1):
SqlConnection con = new SqlConnection( "server=.;database=Northwind;uid = sa;pwd= ");
SqlDataAdapter sda = new SqlDataAdapter( "select * from Employees ",con);
DataSet ds = new DataSet();
sda.Fill(ds, "Employees ");
GridView2.DataSource = ds;
GridView2.DataBind();
连接(2):
SqlConnection con = new SqlConnection( "server=.;database=NorthWind;uid = sa;pwd= ");
SqlCommand cmd = new SqlCommand( "select * from Employees where EmployeeID= " + TextBox1.Text, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
dr.Close();
con.Close();
------解决方案--------------------针对数据库的连接都是一样的,
一个是用SqlDataAdapter
另一个是SqlCommand