none
How do i convert a System.Data.Dataset object into system.Data.Datatable Object? RRS feed

  • Question

  •  

    The thing is..

    I have a method which should return system.Data.Table object..

    The purpose of this method is to get information about an entity( say employee info) from the database by executing the stored procedures. I have used SqlHelper Class to Execute the Stored Procedure, which returns system.Data.Dataset Object to this method. However, as i mentioned above the method inturn should return a System.Data.Table Object.

     

    So how can i convert a system.Data.Dataset object into a system.Data.DataTable object?

    Sunday, September 30, 2007 12:02 PM

All replies

  • How many tables are in your dataset?

     

     

    Assuming DS is your DataSet and your DataSet has 2 tables;

    DataTable DT1 = new DataTable();

    DataTable DT2 = new DataTable();

     

    DT1 = DS.Tables[0];

    DT2 = DS.Tables[1];

     

    If you know the names of the tables

     

    DT1 = DS.Tables["Table1"];

     

    You can also do this

     

    foreach(DataTable table in DS.Tables)

    {

    DataTable DT = new DataTable(table.TableName);

    }

     

     

    BUT  Why create a new object when you have a perfectly good object to work with. You can just set your DataSet to public or public static and use the extracted informaiton through out all your classes and then use it like this

     

    DS.Tables["Name"].Rows[0]["Column1].ToString();

     

     

     

     

     

    Sunday, September 30, 2007 2:33 PM