Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Am reading one excel using c# code, and am saving it in to datatable
but the column heading in datatable is differnt from the excel.
Column name in excel seems to be trimed. why?

What could be the reason?

Note:My column name in excel is lenghty. ( " 'sdsd' Organisation Name if it is different from the dwiccc Organisation " this is excel column but its coming like

" sdsd' Organisation Name if it is different from the dwiccc Org" in my datatable)

below is the connction string am using
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 8.0");

Please help me to solve this.

Any solution?
Posted
Updated 14-Nov-13 4:48am
v2
Comments
Am Gayathri 14-Nov-13 9:21am    
help..........:( :( :(
Need to close this issue today itself..
Am Gayathri 14-Nov-13 10:48am    
Any solution?
CHill60 14-Nov-13 14:48pm    
I gave you the solution 2 hours before you posted this comment. If that solution doesn't work for you then post a comment against the solution explaining what the problem is now.
Am Gayathri 15-Nov-13 1:45am    
As per your solution i have to trim the column names, Am looking for a solution which doesn't require to change column names.
If there is no solution like that i will do this one.
Thanks a lot...
CHill60 15-Nov-13 4:39am    
If the maximum column length on your database is 64 characters then you will have to live with that or change RDMS.
See Maciej Los' solution regarding aliases if that helps.
I would also advise you to read up on SQL naming standards - they are suggested for a reason - I'll update my solution with a link

Your column name is too long for the database you are trying to store it on.

Stick to 64 characters or less.

Actually MUCH less, this is far too unwieldy as a column name and you should avoid spaces and special characters as well

[Edit]
An example of (good) SQL server naming standards[^]
 
Share this answer
 
v2
Comments
Am Gayathri 14-Nov-13 9:32am    
Thanks for your reply
Maciej Los 14-Nov-13 16:30pm    
+5!
Please, see my answer ;)
kiquenet.com 25-Jul-18 10:00am    
not found
CHill60 25-Jul-18 10:14am    
Thank you for letting me know that the link is broken. Here is an alternative - an article here on CodeProject
SQL Server Table and Column Naming Conventions[^]
CHill60 25-Jul-18 10:17am    
Here is the fixed link SQL server naming conventions - they moved the document. Warning - this link is to a PDF
Solution 1 is very, good...

I would recommend you to use aliases ;)

Please, read it: Getting Data between Excel and SQL Server using ODBC [^]. There you'll find many useful information.
 
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