4

I am Using OLEDB to read Excel Sheet with C#. In that Column header Name is "Sr.No." in my "Sheet1". When i fetch Excel Sheet Data into my Datatable , i am getting "Sr#No#" as a column header name instead of original one. Can you please tell me why it’s happening so? And what is the solution for the same.

Thanks.

2 Answers 2

4

After some testing I've found out that OleDB converts the following characters:

. becomes #

! becomes _

` becomes _

[ becomes (

] becomes )

All the other characters are read correctly. Hope this helps someone.

Best Regards.

Sign up to request clarification or add additional context in comments.

Comments

2

Googling around suggests that this is an inherent feature of OLEDB, rather than being anything to do with Excel - it seems to simply not like periods (.) in column names.

My suggestions would be either to cope with it - it seems to be a deterministic replacement of .s with #s - or if possible use an alternative means of reading Excel data from C# (search this site for alternatives).

1 Comment

Yep! When using OLEDB you are treating the excel file like a database table. The rules for database (OLEDB ones anyway) tables apply. As AakashM said you need to deal with the replacement in code post oledb read, or replace with another method of reading the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.