Click here to Skip to main content
16,005,178 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
please help
i want to fetch only those column of excel having data.
when i am fetching all column i get error while excel adapter fill dataset ExcelAdapter.Fill(ExcelDataSet);"
C#
Error is "to many value"

so i want to fetch those column having data in excel.
thanks in advance
my code is

C#
OleDbConnection con = null;
string FilePath = Server.MapPath(Strfilename);
string FileExt = System.IO.Path.GetExtension(FilePath);
if (FileExt == ".xls")
{
con = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + FilePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"");
}
con.Open();
DataTable dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
Session["Dtexl"] = dt;
if (dt.Rows.Count > 0)
{
string getExcelSheetName = dt.Rows[0]["Table_Name"].ToString();
OleDbCommand ExcelCommand = new OleDbCommand(@"SELECT * FROM [" + getExcelSheetName + @"]", con);
OleDbDataAdapter ExcelAdapter = new OleDbDataAdapter(ExcelCommand);
DataSet ExcelDataSet = new DataSet();
ExcelAdapter.Fill(ExcelDataSet);
Posted
Updated 26-Jun-14 20:32pm
v3

1 solution

hi,

is your Data table Contains over values like more the 10000(ten thousand rows ) or else when u get is error exactly.
 
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