Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 13-Feb-13 0:53am
Comments
Rahul Dhoble at 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 at 13-Feb-13 6:45am
   
Short and to the point, +5!
Richard MacCutchan at 13-Feb-13 7:11am
   
Why use 50 words when 7 will do? :)
Maciej Los at 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
0 OriginalGriff 290
1 Jochen Arndt 165
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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