locked
convert DataTable to DataSet RRS feed

  • Question

  • User1974358783 posted
    <color="#6633cc">Edited by SomeNewKid. Please post code between </color><color="#000000"><</color>code><color="#6633cc"> and </color><color="#000000"><</color>/code><color="#6633cc"> tags.</color>
    Can anybody tell me how convert DataTable to DataSet ? public DataTable GetTable(string strTableName) { try { if (_oleConn ==null) Open(); if (_oleConn.State != ConnectionState.Open) throw new Exception("Connection cannot open error."); if (SetSheetQuerySelect()==false) return null; //Fill table OleDbDataAdapter oleAdapter = new OleDbDataAdapter(); oleAdapter.SelectCommand = _oleCmdSelect; DataTable dt = new DataTable(strTableName); oleAdapter.FillSchema(dt,SchemaType.Source); oleAdapter.Fill(dt); if (this.Headers ==false) { if (_strSheetRange.IndexOf(":")>0) { string FirstCol = _strSheetRange.Substring(0,_strSheetRange.IndexOf(":")-1); int intCol = this.ColNumber(FirstCol); for (int intI=0;intI
    Tuesday, December 14, 2004 12:42 AM

All replies

  • User-294030300 posted
    DataSet ds = new DataSet(); ds.Tables.Add(dt); Brian
    Tuesday, December 14, 2004 8:45 AM
  • User-46330738 posted

    Yea, its working fine for me.

    Good Idea..

    Friday, May 10, 2013 5:14 AM
  • User-1800438376 posted

    DataSet ds = new DataSet();

    ds.Tables.Add(dt);

    ds.Tables.Add(dt1);

    ds.Tables.Add(dt2);

    where dt,dt1,dt2 is the datatable that you want to add it on DataSet.

    to retreive the DataTable

    if(ds.Tables.Count = 3) {

    dt = ds.tables[0];

    dt1 = ds.Tables[1];

    dt2 = ds.Tables[2];

    }

    Friday, May 10, 2013 5:59 AM
  • User-782344923 posted

    Hi,

    Use this

    DataTable dt = new DataTable();
    DataSet ds = new DataSet();
    
    ds.Merge(dt);

    Cheers

    Friday, May 10, 2013 6:10 AM
  • User223678428 posted

    Man, necro'd a post from 2004.  That's awesome!  haha

    Monday, May 13, 2013 4:10 PM