Click here to Skip to main content
15,895,958 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
http://csharpcorner.mindcrackerinc.netdna-cdn.com/forums/uploadfile/50cef0/11092017011035AM/ipmsgclip_s_1510206908_0.png

when i open the excel file above error is occurs, and another error inside the excel opening(Excel was able to open the file by repairing or removing the unreadable content) i click the yes and save as another file and upload the excel.but after the upload many lines are ignored how to fix it.


What I have tried:

i follow some online solutions and apply but not working.
if i copy the data and paste to new excel doc and upload no problem is occurs successfully uploaded.
Posted
Updated 8-Nov-17 19:56pm
Comments
Sibasisjena 9-Nov-17 1:32am    
The excel sheet might have corrupted. Please create a sample excel sheet and try to read that to datatable. Please find the solution given below.

Read-Excel-Sheet-Data-into-DataTable

1 solution

DataTable dtResult = null;
int totalSheet = 0; //No of sheets on excel file
using(OleDbConnection objConn = new OleDbConnection(@
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"))
{
objConn.Open();
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter oleda = new OleDbDataAdapter();
DataSet ds = new DataSet();
DataTable dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string sheetName = string.Empty;
if (dt != null)
{
var tempDataTable = (from dataRow in dt.AsEnumerable()
where!dataRow["TABLE_NAME"].ToString().Contains("FilterDatabase")
select dataRow).CopyToDataTable();
dt = tempDataTable;
totalSheet = dt.Rows.Count;
sheetName = dt.Rows[0]["TABLE_NAME"].ToString();
}
cmd.Connection = objConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM [" + sheetName + "]";
oleda = new OleDbDataAdapter(cmd);
oleda.Fill(ds, "excelData");
dtResult = ds.Tables["excelData"];
objConn.Close();
return dtResult; //Returning Dattable
}
 
Share this answer
 

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