By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,966 Members | 812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,966 IT Pros & Developers. It's quick & easy.

Trouble with OleDb data extract

P: n/a
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.

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 sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=Excel 8.0;"
Dim objConnXL As New OleDbConnection(sConnectionString)

''''Create Data Adapter and Data Set.
Dim Employee Select As New OleDbCommand("SELECT * FROM
Employee where RowNum > 0 ", objConnXL)
Dim Employee Adapter As New OleDbDataAdapter()
Employee Adapter.SelectCommand = Employee Select
Dim Employee Dataset As New DataSet()
Employee Adapter.Fill(Employee Dataset, "XLData")

'DataGrid1.DataSource = Employee Dataset.Tables(0).DefaultView
'DataGrid1.DataBind()
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a


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

P: n/a


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

P: n/a
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******@mcdermott.com (Brian Hanson) wrote in message news:<16**************************@posting.google. 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.SqlCommand 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 sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=Excel 8.0;"
Dim objConnXL As New OleDbConnection(sConnectionString)

''''Create Data Adapter and Data Set.
Dim Employee Select As New OleDbCommand("SELECT * FROM
Employee where RowNum > 0 ", objConnXL)
Dim Employee Adapter As New OleDbDataAdapter()
Employee Adapter.SelectCommand = Employee Select
Dim Employee Dataset As New DataSet()
Employee Adapter.Fill(Employee Dataset, "XLData")

'DataGrid1.DataSource = Employee Dataset.Tables(0).DefaultView
'DataGrid1.DataBind()
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

P: n/a

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.ClearContents
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

P: n/a
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

P: n/a

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_machine|software\microsoft\jet\4.0\engi nes\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 sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"_
& "Data Source = " test.xls" _
& ";" & "Extended Properties=""Excel 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
3v8ie02vcld5j7adc3p3pj9j3c0tp5%404ax.com&rnum=2&pr ev=/groups%3Fq%3Dimex%
2B%2B%2BCould%2Bnot%2Bfind%2Binstallable%2BISAM%2B oledb%26ie%3DUTF-8%26o
e%3DUTF-8%26hl%3Den%26btnG%3DGoogle%2BSearch

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.