locked
Import from Excel to Sql RRS feed

  • Question

  • User-1499457942 posted

    Hi 

      IN below code if i upload first 4 values then it works . If i upload 6 values then it gives error No Value given for one or more required parameters

    dtExcelData.Columns.AddRange(new DataColumn[6] { new DataColumn("Category", typeof(string)),
                        new DataColumn("Name", typeof(string)),
                        new DataColumn("Department",typeof(string)),
                        new DataColumn("Item", typeof(string)),
                        new DataColumn("D1", typeof(decimal)),
                        new DataColumn("B1",typeof(decimal))
    
    using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT Category,Name,Department,Item,D1,B1 FROM [" + sheet1 + "]", cnnExcel))
                        
                        {
                            oda.Fill(dtExcelData);
    
                        }
    SqlBulkCopy objbulkInsert = new SqlBulkCopy(con);
    objbulkInsert.DestinationTableName = "[Test]";
    objbulkInsert.WriteToServer(dtExcelData);

    Thanks

    Sunday, December 16, 2018 10:34 AM

Answers

  • User-893317190 posted

    Hi JagjitSingh,

    Please check whether there are Category,Name,Department,Item,D1,B1 columns in your excel files,this may be because there are no such columns in your excel files.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 17, 2018 1:37 AM

All replies

  • User-893317190 posted

    Hi JagjitSingh,

    Please check whether there are Category,Name,Department,Item,D1,B1 columns in your excel files,this may be because there are no such columns in your excel files.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 17, 2018 1:37 AM
  • User-1499457942 posted

    Hi

       In Excel Sheet there are all Columns

    Thanks

    Monday, December 17, 2018 4:45 AM
  • User409696431 posted

    Is the data you are providing consistent with the data types, and nullable or not, definitions for the database columns?  (And are the column names identical?)

    Monday, December 17, 2018 6:05 AM