How to fill Dataset with multiple tables?

前端 未结 8 561
小鲜肉
小鲜肉 2020-11-29 07:20

I\'m trying to fill DataSet which contains 2 tables with one to many relationship. I\'m using DataReader to achieve this :

    public DataSet SelectOne(int i         


        
相关标签:
8条回答
  • 2020-11-29 08:19

    Here is very good answer of your question

    see the example mentioned on above MSDN page :-

    0 讨论(0)
  • 2020-11-29 08:19

    Method Load of DataTable executes NextResult on the DataReader, so you shouldn't call NextResult explicitly when using Load, otherwise odd tables in the sequence would be omitted.

    Here is a generic solution to load multiple tables using a DataReader.

    // your command initialization code here
    // ...
    DataSet ds = new DataSet();
    DataTable t;
    using (DbDataReader reader = command.ExecuteReader())
    {
      while (!reader.IsClosed)
      {
        t = new DataTable();
        t.Load(rs);
        ds.Tables.Add(t);
      }
    }
    
    0 讨论(0)
提交回复
热议问题