使用DataAdapter的Fill方法返回包含多个数据表的DataSet

在DataAdapter的SelectCommand的CommandText中直接采用批查询

例如:

 strSql = "SELECT * FROM Orders;SELECT * FROM Customers";

 SqlDataAdapter daData = new SqlDataAdapter(strSql,new SqlConnection("server=XLZHU;User ID=sa;Password=111111;database=Northwind"));

 //daData.TableMappings.Add("Table","Order_Info");

 //daData.TableMappings.Add("Table1","Customer_Info");

 DataSet dsData = new DataSet();

 daData.Fill(dsData); 

这样,dsData中就会有两个DataTable,分别为Table和Table1(去掉注释名称就为Order_Info和Customer_Info)

你可能感兴趣的:(Adapter)