C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » SQL »

Code Geting column name of Excel sheet to create sql table


Posted Date: 25 Nov 2008    Resource Type: Code Snippets    Category: SQL
Author: Abhinav MisraMember Level: Silver    
Rating: 1 out of 5Points: 7



HI all

This find the column name of excel sheet
so that we can create data base of same at run time........


{
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\mca23.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

OleDbConnection con = new OleDbConnection(excelConnectionString);
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", con);
OleDbDataReader rdr = cmd.ExecuteReader();
DataTable schema = rdr.GetSchemaTable();

foreach (DataRow row in schema.Rows)
{
int i = 0;
foreach (DataColumn col in schema.Columns)
{ //
if (i == 0)
{
Response.Write(row[0]);
}
i = i + 1;
}
}
rdr.Close();
}



Responses

Author: ravinder semwal    28 Nov 2008Member Level: Bronze   Points : 0
thaxs for the code
it is good
keep posting


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
ADO.NET  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to create a user account database
Previous Resource: Date time function
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use