Solved

oledbexception : too many fields defined

Posted on 2004-09-30
8
2,492 Views
Last Modified: 2008-01-09
hi

I want to parse an excel file and store the results in a dataset.
I am using microsoft JET oledb for this.

the problem arises when there are extra columns in the excel file (even though they are not defined ), and i get the oledb exception: too many fields defined (when there are no columns in the excel file that are really "data"), since i am filling a dataset from a query for the above table selected.

say for example some excel file has 5 columns and 50 rows. every time i run my program on a new excel file that i receive, i need to make sure, all the EXTRA columns starting from column 6 to the end of whatever columns, are selected and then DELETED.

If i do the above step only my program runs fine or else ends up with the exception.

now to my question: is there a way from the program to let the program delete those EXTRA columns, so i dont end up in that exception that i get. ??
or else there is another way out of this situation and NOT get that exception.

thanks
messageman
0
Comment
Question by:messageforums
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 12198503
Can you show some code how you read the data from the excel file? The commands you execute, etc.?
0
 

Author Comment

by:messageforums
ID: 12201761
//Connect to Workbook
      OleDbConnection oleConn = new OleDbConnection();
      oleConn.ConnectionString = strConn;
      oleConn.Open();

//Sheet1 must be named accordingly
      OleDbDataAdapter oleCmd = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", oleConn);

      DataSet oDS = new DataSet();
                oleCmd.Fill(oDS);

      int oleRowCount = 1;
      //oDS.Tables.
      foreach(DataRow oleRow in oDS.Tables[0].Rows)
      {
                        // Do stuff here
                  }


one more thing is the field names in the excel have spaces in thehm (ex: "student ID", etc - in case we want to include them in the command). so i dont think we can put that as the field name

another issue is that i am selecting SHEET1. the program mandates me to name that particular worksheet to be Sheet1, inorder for my program to work. any way to escape this ?

thx
messageman
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12202277
Do you have any print ranges set?  You might be limited to 256 columns, and that could happen if you set a print range.

Bob
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:messageforums
ID: 12202452
hi ,


>>Do you have any print ranges set?  You might be limited to 256 columns, and that could happen if you set a print range.

can you please give me some code how to set it and the complete code that could be run and still satisfy the above requirements ?


thank you
messageman
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12202856
No, I mean that you shouldn't have any ranges set.  Excel interaction through OleDb is kind of stupid.

Bob
0
 

Author Comment

by:messageforums
ID: 12203761
hi bob

> Excel interaction through OleDb is kind of stupid.

I am new to all this stuff. so do excuse me for the quesitons. if interaction with excel through oledb is stupid. is there a better way. ? if so what way can i do it

please let me know.


messageman
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 60 total points
ID: 12203776
Maybe you can use Excel automation.   It might bring in the possibility of more hassles, but provides you with more specific information about columns, then the Jet engine provides.  Plus, you can do so many more things with it.  But, it also means that the client needs to have Excel.  So, if you are developing for an external client, then the OleDb is a simpler approach.

Bob
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question