Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
RDBurmon 13-Feb-13 5:59am    
Which language are you using ? C# or VB.net

 
Share this answer
 
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 ;)
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(':');
 
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