Click here to Skip to main content
15,797,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
I am using VS2010 Wpf application with c#. I am read the xlsx file using oledb connection its working fine but after reading my xlsx some data missing in the reading data set.

Here i attached my Coding and i have the screen shot of the problem but here no option is there for attaching screen shot.

private DataTable ReadExcel(string tabName)
           DataTable retTbl = new DataTable();
           DataTable dtRead = new DataTable();

               System.Data.OleDb.OleDbConnection MyConnection;
               System.Data.DataSet DtSet;
               System.Data.OleDb.OleDbDataAdapter MyCommand;
               MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\';Extended Properties=Excel 8.0;");
               MyConnection = conn;
               MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [" + tabName + "$]", MyConnection);
               MyCommand.TableMappings.Add("Table", "TestTable");
               DtSet = new System.Data.DataSet();
               dtRead = DtSet.Tables[0];

           catch (Exception ex)

           return dtRead;

Consider as Excel Columns

' c1' c2 ' c3'
' 1 ' Test ' 0 '
' 3 ' 1 ' 4 '

After Read the Excel:

' c1' c2 ' c3'
' 1 ' ' 0 '
' 3 ' 1 ' 4 '

see the Above example "Test" is missing after Read excel.

sorry for my English..

Thanks all,
karthik M

What I have tried:

i am tried to read the XLSX file.
Updated 31-Jul-19 5:38am
OriginalGriff 9-May-16 2:58am    
What's the problem?
Any error message? What happens that you didn't expect, or doesn't happen that you did?
And don't give us screen shots: explain, and copy and paste error messages.
Use the "Improve question" widget to edit your question and provide better information.
Karthik_Mahalingam 9-May-16 4:05am    
What data missing, Please be more specific.
Use Improve question to add more info.
wilford.ramsey 28-Jun-17 7:42am    
You should try this code to read a .xlsx file in C#.

You need the Microsoft ACE engine to read XLSX files. See Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^].
Share this answer
A quick thought: you say it's an XLSX file, but two things I note:
1) It's an XLS extension, not an XLSX - XLS files aren't the same at all.
2) You're trying to read it as Excel 8.0, but XLSX files weren't introduced until V12.0 with Excel 2007: Microsoft Excel - Wikipedia, the free encyclopedia[^]
So check your file: see what's in it.
Share this answer
it looks only string data gets missing, to resole this, Use 'IMEX=1' in connection string it helps you to read data in string format
Use this one when you want to treat all data in the file as text, overriding Excels column type "General" to guess what type of data is in the column.
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;
Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";

hope it helps
Share this answer
Member 11889799 11-May-16 1:32am    
Hi prasad,
Thanks for your response its working fine.Thanks you lot.
koolprasad2003 11-May-16 2:07am    
Please accept it as solution if it resolved :)

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