Click here to Skip to main content
15,078,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need to display excel data in sql database without duplication..
I have use file upload control in and a Button.
I need to save the excel data in database on button click event without duplication.

this is my code which is showing an error..
protected void btnsave_Click(object sender, EventArgs e)
        //Create connection string to Excel work book
            string excelConnectionString =
            @"Provider=Microsoft.Jet.OLEDB.4.0;" + 
            "Data Source=/BACKUP C DATA140312/Desktop/pratham/ActiveSub-Brokers" 
            + Server.MapPath("Book1.xls") + ";" + "Extended Properties=Excel 8.0";

            //Create Connection to Excel work book
            OleDbConnection excelConnection =
            new OleDbConnection(excelConnectionString);

            //Create OleDbCommand to fetch data from Excel
            OleDbCommand cmd = new OleDbCommand
            ("Select * from [Book1$]",

            OleDbDataReader dReader;
            dReader = cmd.ExecuteReader();

            SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
            sqlBulk.DestinationTableName = "tblActiveSubBroker";
            //sqlBulk.ColumnMappings.Add("ID", "ID");
            //sqlBulk.ColumnMappings.Add("Name", "Name");

this shows error

Failure creating file.

Thanks in advance
Updated 7-Jun-12 18:15pm

Similar issue with atleast two possible reasons discussed and that helped others:
Excel import from Sharepoint Failure creating file[^]
ASP.NET error "Failure creating file."[^]
Try them and see if they help.
pratham2587 8-Jun-12 5:31am
Issue is not resolved and i m not able to store the excel data in sql database
Issue is Resolved to import excel data to sql database....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900