Click here to Skip to main content
15,031,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am uploading excel file , copy to data set .

using this code,

DataSet ds = new DataSet();
       OleDbCommand excelCommand = new OleDbCommand();
       OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
       string excelConnStr;

       if (Extension != ".xlsx")
           excelConnStr = String.Format("Provider=Microsoft.Jet.OleDb.4.0; Data Source = {0}; Extended Properties =\"Excel 8.0", filelocation);
           excelConnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = {0}; Extended Properties =\"Excel 12.0", filelocation);


       OleDbConnection excelConn = new OleDbConnection(excelConnStr);
       DataTable dt= new DataTable();
       excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
       excelDataAdapter.SelectCommand = excelCommand;

Records in data table are not correct.

if excel has 1 row, table has 3 rows..

How can we resolve this?
Prerak Patel 13-Jan-12 1:06am
Check if input excel file has merged rows.

1 solution

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