locked
import excel data to data set using asp.net C# RRS feed

  • Question

  • Hi,

    How to import highly formatted excel data to data set.

    for example

      10 column each one have sub columns. heading columns etc

    How can we import to dataset

    • Moved by Kristin Xie Friday, September 25, 2015 8:40 AM
    Thursday, September 24, 2015 10:59 AM

Answers

  • Hi Sudeesh IG,

    As your title said, using asp.net C#,this forum is for C# code issues in specific. For better support, please post in the following forums.
    http://forums.asp.net/

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Friday, September 25, 2015 8:42 AM
    • Proposed as answer by Just Karl Friday, September 25, 2015 2:11 PM
    • Marked as answer by Just Karl Friday, October 23, 2015 10:52 PM
    Friday, September 25, 2015 8:40 AM

All replies

  • Hello There,

    please refer below link

    http://stackoverflow.com/questions/18006318/how-to-import-all-the-excel-sheets-to-dataset-in-c-sharp

    Cheers

    Dinesh

    • Proposed as answer by Dinesh Gabhane Thursday, September 24, 2015 11:08 AM
    Thursday, September 24, 2015 11:08 AM
  • I'm not sure if I understood you correctly, but I presume that each of those 10 columns should be imported into a separate data table and those sub columns represent the columns for a data table, is that correct?

    So in short this is how I pictured your excel file looks like:

    In that case here is what you can do with a help of this C# library for excel's workbooks:

    DataSet ds = new DataSet();
    ExcelFile workbook = ExcelFile.Load("Sample.xlsx");
    ExcelWorksheet worksheet = workbook.Worksheets[0];
    
    // Creates a DataTable with columns defined in A2 - B2
    // and records defined in A3 - B10.
    DataTable table1 = worksheet.CreateDataTable(
        new CreateDataTableOptions("A2", 9, 2) { ColumnHeaders = true });
    
    // Sets the table's name to "Table 1".
    table1.TableName = worksheet.Cells["A1"].StringValue;
    ds.Tables.Add(table1);
    
    // Creates a DataTable with columns defined in C2 - E2
    // and records defined in C3 - E10.
    DataTable table2 = worksheet.CreateDataTable(
        new CreateDataTableOptions("C2", 9, 3) { ColumnHeaders = true });
    
    // Sets the table's name to "Table 2".
    table2.TableName = worksheet.Cells["C1"].StringValue;
    ds.Tables.Add(table2);

    This will generate a DataSet and add those two DataTable with an appropriate header columns into it. You can find more information on this article about importing an excel files to a data set object.

    Friday, September 25, 2015 8:33 AM
  • Hi Sudeesh IG,

    As your title said, using asp.net C#,this forum is for C# code issues in specific. For better support, please post in the following forums.
    http://forums.asp.net/

    Best regards,

    kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Kristin Xie Friday, September 25, 2015 8:42 AM
    • Proposed as answer by Just Karl Friday, September 25, 2015 2:11 PM
    • Marked as answer by Just Karl Friday, October 23, 2015 10:52 PM
    Friday, September 25, 2015 8:40 AM