How to determine column type in Excel file using C#

I have created a C# program to read an Excel file and insert records into SQL. Every now and then it fails and it fails because one of the columns is not defined the same as in all the other files. This particular column contains a 14 digit string of digits. Most times it is defined in Excel as number but every now and then it is defined as text. Is there a way using C# to determine the type of a column or cell so I can adjust the code to convert one way or the other?
LVL 1
rwheeler23Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ares KurkluSoftware EngineerCommented:
Hi,
I don't think it is possible to determine the type of a column, I am not sure how you are reading the values but initially if you read every field as string then you should be able do some checks on that string variable to find the type. Basically you may have to validate cell basis.

there are many ways to do that, you can use functions like:
long.TryParse , int.TryParse etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
check the source file, is that possible that column's values had been converted to text (like something with +e bla bla..) before you're importing it to your database?
rwheeler23Author Commented:
They are supposedly using the same template over and over again. I noticed this when I was ding the import manually using SSMS.
rwheeler23Author Commented:
Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.