473,695 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with OleDb data extract

Hi,

I have an unusual problem that just showed its ugly head at a pretty
bad time. I have an asp.net (VB) app that takes data from an Excel
sheet and puts it into SQL Server. I get the data out of Excel using
OleDB, and suddenly, some of the data was not being extracted from
Excel.

I use OleDb for the extract into a DataTable and from there an
SqlClient.SqlCo mmand to put it into SQL Server.

I put the results of the OleDb extract into a datagrid to see if the
problem was there or the SqlClient insert. The datagrid showed
missing data, even before I got to the SQL insert. Here's my code
(roughly):

Dim sConnectionStri ng As String = "Provider=Micro soft.Jet.OLEDB. 4.0;"
_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=Exce l 8.0;"
Dim objConnXL As New OleDbConnection (sConnectionStr ing)

''''Create Data Adapter and Data Set.
Dim Employee Select As New OleDbCommand("S ELECT * FROM
Employee where RowNum > 0 ", objConnXL)
Dim Employee Adapter As New OleDbDataAdapte r()
Employee Adapter.SelectC ommand = Employee Select
Dim Employee Dataset As New DataSet()
Employee Adapter.Fill(Em ployee Dataset, "XLData")

'DataGrid1.Data Source = Employee Dataset.Tables( 0).DefaultView
'DataGrid1.Data Bind()
Assume the following data from an Excel namespace called Employee:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 12345 1
Bill Jones 456 North LA CA 54321 2
The extract suddenly omitted the zip 12345, but displayed the other 13
pieces of data fine. I can see the data in the Excel sheet. This has
been working fine for several months, and of course, last week we went
live, go figure.

If anyone has run into this or anything like it, please give a yell.

Thanks.
Nov 18 '05 #1
9 3386
Hi Brian,

I am not sure about the exact meaning of "The extract suddenly omitted the
zip 12345, but displayed the other 13 pieces of data fine." As I
understand, you mean that you lost the first row. Please remove "where
RowNum > 0" and test this issue again.

In addition, I believe that the following article is useful to you. Please
refer to it carefully.

Read Excel files from ASP.NET
http://www.aspfree.com/examples/766,1/examples.aspx
"...
This page provides a simple example of how to query an Excel spreadsheet
from an ASP.NET page using either C# or VB.NET.
..."

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #2
Hi Brian,

I am not sure about the exact meaning of "The extract suddenly omitted the
zip 12345, but displayed the other 13 pieces of data fine." As I
understand, you mean that you lost the first row. Please remove "where
RowNum > 0" and test this issue again.

In addition, I believe that the following article is useful to you. Please
refer to it carefully.

Read Excel files from ASP.NET
http://www.aspfree.com/examples/766,1/examples.aspx
"...
This page provides a simple example of how to query an Excel spreadsheet
from an ASP.NET page using either C# or VB.NET.
..."

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #3


Hi Jacob,

Thanks for the reply. What I meant by "The extract suddenly omitted the
zip 12345, but displayed the other 13 pieces of data fine” is this.

Assume the Excel data looking like this:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 12345 1
Bill Jones 456 North LA CA 54321 2
Then assume the datagrid that selects everything from the Excel sheet
looks like this:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 1
Bill Jones 456 North LA CA 54321 2
All data is selected from the Excel sheet except for one field.

Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4


Hi Jacob,

Thanks for the reply. What I meant by "The extract suddenly omitted the
zip 12345, but displayed the other 13 pieces of data fine” is this.

Assume the Excel data looking like this:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 12345 1
Bill Jones 456 North LA CA 54321 2
Then assume the datagrid that selects everything from the Excel sheet
looks like this:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 1
Bill Jones 456 North LA CA 54321 2
All data is selected from the Excel sheet except for one field.

Thanks.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
I assume by 'Excel namespace' you mean 'defined name' or 'named
range'. Have you checked its definition to ensure it is still
referencing the same Excel range i.e. including the header row?

BTW you should, for all sorts of reasons, seriously consider changing
your SQL from

SELECT * FROM ...

to

SELECT First, Last, Addr, City, State, Zip, RowNum FROM ...

You never know, it may help with the current problem.

--

bd******@mcderm ott.com (Brian Hanson) wrote in message news:<16******* *************** ****@posting.go ogle.com>...
Hi,

I have an unusual problem that just showed its ugly head at a pretty
bad time. I have an asp.net (VB) app that takes data from an Excel
sheet and puts it into SQL Server. I get the data out of Excel using
OleDB, and suddenly, some of the data was not being extracted from
Excel.

I use OleDb for the extract into a DataTable and from there an
SqlClient.SqlCo mmand to put it into SQL Server.

I put the results of the OleDb extract into a datagrid to see if the
problem was there or the SqlClient insert. The datagrid showed
missing data, even before I got to the SQL insert. Here's my code
(roughly):

Dim sConnectionStri ng As String = "Provider=Micro soft.Jet.OLEDB. 4.0;"
_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=Exce l 8.0;"
Dim objConnXL As New OleDbConnection (sConnectionStr ing)

''''Create Data Adapter and Data Set.
Dim Employee Select As New OleDbCommand("S ELECT * FROM
Employee where RowNum > 0 ", objConnXL)
Dim Employee Adapter As New OleDbDataAdapte r()
Employee Adapter.SelectC ommand = Employee Select
Dim Employee Dataset As New DataSet()
Employee Adapter.Fill(Em ployee Dataset, "XLData")

'DataGrid1.Data Source = Employee Dataset.Tables( 0).DefaultView
'DataGrid1.Data Bind()
Assume the following data from an Excel namespace called Employee:

First Last Addr City State Zip RowNum
Joe Smith 123 Main NY NY 12345 1
Bill Jones 456 North LA CA 54321 2
The extract suddenly omitted the zip 12345, but displayed the other 13
pieces of data fine. I can see the data in the Excel sheet. This has
been working fine for several months, and of course, last week we went
live, go figure.

If anyone has run into this or anything like it, please give a yell.

Thanks.

Nov 18 '05 #6

Thank you both for your replies, here’s what I’ve learned in the last
few hours. First, by Excel namespace I did mean the named range, and it
has not changed. Also, I was using column names in my select vs. the
select * method.

What I have learned is the sequence of events while the user fills out
the Excel form is what triggers this, but I can’t assume that this is
the whole story. The column in question is originally set to datatype
Text. “It may be a number, but is displayed as entered.” We have a
button that executes the Cell.Clear function in VBA code. This was the
problem. It changed the column datatype from Text to General (and
possibly done more than that) now the OleDb extract will not read that
data.

We have fixed the problem going forward by using Cell.ClearConte nts
instead of Cell.Clear, but we still have existing Excel forms that I
need to read data from. I have manually switched the datatype from
General back to Text, but it still will not read the data. I have tried
to do a conversion from within the OleDb select statement, but it says
the value I am trying to convert is null gives me an error.

One other weird thing that I have noticed but am not sure is important.
When the data is originally entered into a field of type Text, it is
right justified in the cell. Once I do the Cell.Clear and it changes to
General data type, the data is left justified in the cell. I then
change the type back to Text, but the data remains left justified.
Final result, I still cannot get the data out of existing Excel sheets
via the OleDbCommand.

Thanks again.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7
Hi Brian,

Thank you for your update. It seems to be a strange issue.

Have you tested the example I mentioned before?

Read Excel files from ASP.NET
http://www.aspfree.com/examples/766,1/examples.aspx
"...
This page provides a simple example of how to query an Excel spreadsheet
from an ASP.NET page using either C# or VB.NET.
..."

Can you reproduce the same problem the above sample? I certainly appreciate
your time.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #8

Hi,

FYI, we got our prob fixed & I hope this doesn't show twice. Setting
the IMEX =1 property of the connection string forced the data to be read
as text. Actually, it forces this registry setting:

'
hkey_local_mach ine|software\mi crosoft\jet\4.0 \engines\excel\ ImportMixedT
ypes.

It tells Excel how to treat mixed datatypes and was already set to text.
Apparently, the IMEX setting enforces the registry setting.
Dim sConnectionStri ng As String = "Provider=Micro soft.Jet.OLEDB. 4.0;"_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=""Ex cel 8.0; IMEX=1; """
That alone was giving an error of “Could not find installable ISAM”. It
was not untill the extra “” were added to the extended properties
section that it worked.

This was the post that worked for me:

http://groups.google.com/groups?hl=e...8&threadm=ebql
3v8ie02vcld5j7a dc3p3pj9j3c0tp5 %404ax.com&rnum =2&prev=/groups%3Fq%3Dim ex%
2B%2B%2BCould%2 Bnot%2Bfind%2Bi nstallable%2BIS AM%2Boledb%26ie %3DUTF-8%26o
e%3DUTF-8%26hl%3Den%26b tnG%3DGoogle%2B Search

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #9
Hi Brian,

Thank you very much for sharing your solution. It is helpful to everybody
here.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
21827
by: TF | last post by:
Hi, I have to access data from a comma delimited file in .net windows application (VB.net or C#). I am using Microsoft.Jet.OLEDB.4.0 provider for this purpose. Now the problem is when i extract data from a file with extension csv or txt it works fine but as soon as i change the extension, like 'log' or 'abc' it gives following error in 'Fill' function of 'OleDbDataAdapter': Cannot update. Database or object is read-only
2
23929
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table but the table column names. I've seen other posts that suggest using the SQL command DESCRIBE but I can't get it to work for some reason. Other posts have code samples but they're written in VB which I am not familiar with. I
9
4754
by: Pam Ammond | last post by:
I need the code to update the database when Save is clicked and a text field has changed. This should be very easy since I used Microsoft's wizards for the OleDBAdapter and OleDBConnection, and DataSet; and all I'm doing is showing one record in text fields, allowing the user to modify the text fields, and then updating the database again when the user clicks the Save button. The fields already show the correct data record since I have...
1
6881
by: T8 | last post by:
I have a asp.net (framework 1.1) site interfacing against SQL 2000. It runs like a charm 99% of the time but once in a while I get the following "unspecified error". Sometimes it would resolve by itself (asp.net recycled?); it also can be solved by restarting IIS. Any ideas what cause(s) this to happen? System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbDataReader.ProcessResults(Int32 hr) at...
0
302
by: Brian Hanson | last post by:
Hi, I have an unusual problem that just showed its ugly head at a pretty bad time. I have an asp.net (VB) app that takes data from an Excel sheet and puts it into SQL Server. I get the data out of Excel using OleDB, and suddenly, some of the data was not being extracted from Excel. I use OleDb for the extract into a DataTable and from there an SqlClient.SqlCommand to put it into SQL Server.
3
8824
by: Brian Foree | last post by:
I am developing an ASP.NET application that uses Access 2000 as its backend, and have just started getting the following error on 2 ASP.NET pages that had been working until late last week (and I don't think I made any changes to either page other than changing the user control that creates the header). Server Error in '/myApp' Application. ---------------------------------------------------------------------------- ----
0
5655
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at TryThis.Form1.save() in C:\Documents and Settings\Nick\My Documents\...
2
1490
by: AndyJ | last post by:
Hi and thanks in advance for any assistance recieved, There is most likely a simple solution to this as usual... I am trying to access data from an Excell worksheet using ADO. The problem is that the OleDbCommand does not seem to recognise the Date parameter in the command string. Code follows:
1
2038
by: John Wright | last post by:
I am running a console application that connects to an Access database (8 million rows) and converts it to a text file and then cleans and compacts the database. When it runs I get the following error: The CLR has been unable to transition from COM context 0x1a2008 to COM context 0x1a2178 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long...
2
1885
by: rocketfire97 | last post by:
I'm trying to call a COM object using C# but having no luck getting values back for passed in ref objects. I've tried the same call using VB.NET and can get data back. How would I implement the following in C# This is the method I am calling, which populates ref paramters with results. Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
0
8630
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8568
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8845
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7660
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2272
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.