Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey Guys I have a database with field
Name,Email,Contact,Address,Profile
& i have created a excel sheet with these field & data in it (100 entry).
Now i want to use File-upload Control for browsing these excel sheet & on click of Button Control it automatically fill excel sheet data into database.
So anybody who has a idea kindly share with me. I try over it a lot but doesn't reach to solution. So please kindly share your valuable guidance.
Posted

You may take a look at this discussion: import MS Excel to datatable[^]
 
Share this answer
 
Hey Guys i Solved this.

Hey Guys I solve this 
 
protected void btnSend_Click(object sender, EventArgs e)
    {
        //file upload path
        string path = fileuploadExcel.PostedFile.FileName;
        //Create connection string to Excel work book
        string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + path + ";Extended Properties=Excel 12.0; Persist Security Info=False";
        //Create Connection to Excel work book
        OleDbConnection excelConnection =new OleDbConnection(excelConnectionString);
        //Create OleDbCommand to fetch data from Excel
        OleDbCommand cmd = new OleDbCommand("Select [id],[name],[salary] from [Sheet1$]",excelConnection);
        excelConnection.Open();
        OleDbDataReader dReader;
        dReader = cmd.ExecuteReader();
        SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);
        //Give your Destination table name
        sqlBulk.DestinationTableName = "employee";
        //sqlBulk.DestinationTableName = "Book2";
        sqlBulk.WriteToServer(dReader);
        excelConnection.Close();
        grid();
     }
 
Share this answer
 
Comments
rohit24c 22-Oct-12 6:06am    
hello i have used the same code but it giving exception.



The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

Any suggestions plz

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