0

I am exporting a Excel (.xls) sheet to dataset. In that excel i am having 16 columns. While exporting i am getting the error " TOO MANY FIELDS DEFINED "..

Here is my code part..

{
            string strFilePathOnServer = ConfigurationManager.AppSettings["RevenueDumpFileLocation"];
            String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName + ";Extended Properties=\"Excel 8.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\"";

            string strPostedFileName = RevenueDumpFileUpload.PostedFile.FileName;
            if (strPostedFileName != string.Empty && RevenueDumpFileUpload.PostedFile.ContentLength != 0)
            {

                RevenueDumpFileUpload.PostedFile.SaveAs(Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName);
                RevenueDumpFileUpload.FileContent.Dispose();
            }

            OleDbConnection Exlcon = new OleDbConnection(sConnectionString);
            try
            {
                //Exlcon.Open();
            }
            catch
            {
                return;
            }
            OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [Owner$]", Exlcon);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            objDataset1.Clear();
            objAdapter1.Fill(objDataset1, "XLData");

When crossing the Fill method, i am getting the error...

How to sort out this...

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
RobinHood
  • 2,367
  • 11
  • 46
  • 73

1 Answers1

2

Limit the column to only 250

string sql = "select * from [A1:IU]"; 
Flexo
  • 87,323
  • 22
  • 191
  • 272
Zakari
  • 453
  • 4
  • 15
  • 1
    Is it documented anywhere that the limit is 250 columns? I ran into the same problem with an Excel sheet that had a bunch of extra empty but initialized columns, and just deleting those extra empty columns fixes it. I can't rely on user intervention though, and would like to know that 250 is the definitive max number of columns you can have if you're going to fill a dataset from an excel sheet. – Jim Jul 26 '12 at 17:25
  • sorry for the late response, I was on vacations. Appears to be Jet limitation (check connection string). – Zakari Sep 19 '19 at 19:19