Code Geting column name of Excel sheet to create sql table

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();
}


Comments

Author: ravinder semwal28 Nov 2008 Member Level: Bronze   Points : 0

thaxs for the code
it is good
keep posting



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: