Solved

oledbexception : too many fields defined

Posted on 2004-09-30
8
2,443 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net How to Exit Sub - Exit Form??? 5 57
designing in object programming 12 77
InputLanguage 1 26
Create a WebAPI using a generic return parameter 9 25
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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