?
Solved

oledbexception : too many fields defined

Posted on 2004-09-30
8
Medium Priority
?
2,517 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 120 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

752 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