执行OleDb.OleDbDataAdapter.Fill()的时候,如何让OleDbDataAdapter一次执行2条sql语句从而一下返回2个dataTable,

解决方案 »

  1.   

    我试过了3种写法都不行1:select * from table1,select * from table2
    2:select * from table1  select * from table2
    3:select * from table1;select * from table2
      

  2.   

    参考:
    How do I use ExecuteDataset to return a DataSet containing multiple tables?
    You can retrieve a DataSet containing multiple tables by creating a stored procedure that returns multiple rowsets (either by executing multiple SELECT statements or by making nested calls to other stored procedures), and executing it using the ExecuteDataset method.For example, suppose you have the following stored procedures in your database.CREATE PROCEDURE GetCategories
    AS
    SELECT * FROM Categories
    GO
    CREATE PROCEDURE GetProducts
    AS
    SELECT * FROM Products
      
    You could create a master stored procedure that makes nested calls to these procedures, as illustrated in the following code sample.CREATE PROCEDURE GetCategoriesAndProducts
    AS
    BEGIN
      EXEC GetCategories
      EXEC GetProducts
    END
      
    Executing this master stored procedure with the ExecuteDataset method returns a single DataSet containing two tables; one containing the category data and the other containing the product data.Note   The ExecuteDataset method does not provide a way to assign custom names to the tables returned. The first table is always numbered 0 and named Table, the second is numbered 1 and named Table1, and so on.
      

  3.   

    to: upto(阿球) ,我用的是Access数据库,不支持存储过程。
      

  4.   

    To zr1982930(皮卡丘):如果用一个适配器有没有办法呢?
      

  5.   

    string con = "連接字符串";string sql = "select * from table1;"+
                 "select * from table2";System.Data.OleDb.OleDbDataAdapter daT = new System.Data.OleDb.OleDbDataAdapter(sql,con); daT.TableMappings.Add("Table","1");
    daT.TableMappings.Add("Table1","2");
    DataSet ds = new DataSet();
    daT.Fill(ds);
    ds裏會產生兩個表
      

  6.   

    3:select * from table1;select * from table2
    这个应该可以的
      

  7.   

    The first table is always numbered 0 and named Table, the second is numbered 1 and named Table1, and so on.
      

  8.   

    将SQL语句用分号";"隔开就可以了.
      

  9.   


    select * from table1;select * from table2
    用nextrecord
      

  10.   


    select * from table1;select * from table2
    用nextrecord
      

  11.   

    各位,只要select * from table1;select * from table2一执行就报错:在sql语句结尾之后找到字符。
      

  12.   

    如果是sql server 應該沒問題。
    但在其他數據庫,不知道是否支持這種批查詢方式。
    但他們會有自己的批查詢方式。自己找找看看吧。
      

  13.   

    好象不能这样用的!如果楼主想这样的话,就要在SQL语句做手脚了!
    查一下,可不可以用两个表连成一个这样表。
    不过我觉得做成这样的意义不大,而且就算能够成功,要在前台程序把这两个表分开,都有难度!
      

  14.   

    偶觉得Access不支持同时运行多条SQL语句
    Sql Server可以!