Click here to Skip to main content
12,955,988 members (74,199 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: , +
hiiii.... i want to read column names of excel file and display them in a dropdown list. for that what to do?
pls help me.
Posted 12-Feb-13 23:53pm
Comments
Rahul Dhoble 13-Feb-13 5:59am
   
Which language are you using ? C# or VB.net
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Maciej Los 13-Feb-13 6:45am
   
Short and to the point, +5!
Richard MacCutchan 13-Feb-13 7:11am
   
Why use 50 words when 7 will do? :)
Maciej Los 13-Feb-13 7:21am
   
Good question ;)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

string strFilePath = string.Empty;
string ConnString = string.Empty;
string strCols = string.Empty;
string strRowVal = string.Empty;	   
strFilePath = Server.MapPath("~/upload/csvfiles" );
if (strFileType.ToString().Trim() == ".csv")
{
	ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";Extended Properties=Text;";
}
Conn = new OleDbConnection(ConnString);
Conn.Open();
 
string tablename = "";
if (strFile.IndexOf('/') > 0)
{
	tablename = strFile.Substring(strFile.LastIndexOf("/") + 1);
}
else
{
	Int32 intLastIndex = 0;
	intLastIndex = strFile.LastIndexOf("\\");
	tablename = strFile.Substring(intLastIndex + 1);
}
DataTable dt = new DataTable();
dt = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
 

 
OleDbCommand ocmd = new OleDbCommand("SELECT * FROM [" + tablename + "]", Conn);
 
oda = new OleDbDataAdapter(ocmd);
DataSet dsIn = new DataSet();
oda.Fill(dsIn);
Conn.Close();
foreach (DataColumn DtColumn in dsIn.Tables[0].Columns)
{
	strCols = strCols + DtColumn.ColumnName.Trim() + ":";
}
 
strCols = strCols.Substring(0, strCols.Length - 1);
strColArr = strCols.Split(':');
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,849
CHill60 3,550
Maciej Los 3,223
ppolymorphe 2,060
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100