|
原理:使用DataTable实例的Load方法将原有的DataTable实例中的数据加载到新的DataTable实例中完成合并。 using (SqlConnection conn = new SqlConnection("server=(local);database=Northwind;user id=sa;password=sa;min pool size=4;max pool size=100;Connection Lifetime=30;"))
{ //创建两个DataTable SqlDataAdapter adapter1 = new SqlDataAdapter("Select Top 10 * FROM Products", conn); DataTable table1 = new DataTable(); adapter1.Fill(table1); SqlDataAdapter adapter2 = new SqlDataAdapter("Select Top 10 * FROM Products order By productid Desc", conn); DataTable table2 = new DataTable(); adapter2.Fill(table2); //创建一个新的DataTable并加载前面两个DataTable数据 DataTable table = new DataTable(); table.Load(table1.CreateDataReader()); table.Load(table2.CreateDataReader()); //数据源绑定到GridView GridView1.DataSource = table.DefaultView; GridView1.DataBind(); }
|





骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价