Skip to content

Import excel sheet

Nishant Mane

Asked Jan 26, 2015, 11:50 PM EST1 answer
Share
LinkedInX
How to do i import excel sheet data into my database using only c# application?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi Mane, this is one of the simplest ways that I can think of:
    C#
    DataTable table = ExcelFile.Load("Sample.xlsx")
                                .Worksheets
                                .ActiveWorksheet
                                .CreateDataTable(
                                    new CreateDataTableOptions());
     
    using (var conn = new SqlConnection("Sample connection ..."))
    {
        conn.Open();
        using (var bulkCopy = new SqlBulkCopy(conn))
            bulkCopy.WriteToServer(table);
    }
    The API is from this excel library for .NET.
    You can use that first Load method to read both XLS and XLSX files in .NET.
    0