Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / November 2006



Tip: Looking for answers? Try searching our database.

Excel import to Ado.net - bad record count

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
brett.mack@gmail.com - 21 Nov 2006 21:12 GMT
Hello!
I'm using the code below to import an Excel datasheet into an ado.net
table. The problem is, when I
get to the point where I want to iterate the recods, it always thinks
that there is 999 records in the table! If the table (worksheet) is
larger than that, then it returns an equally fictious number (always
way more).

Does anybody have any idea what I'm doing wrong? I'ts an excel 2003
spreadsheet that I'm reading from. Thanks in advance!

   Sub readSheet()
       Dim excelConn As New System.Data.OleDb.OleDbConnection

       excelConn.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                   "Data Source=C:\MySpreadSheet.xls;"
& _
                                   "Extended Properties=""Excel
8.0;HDR=Yes;"""
       excelConn.Open()
       Dim da As New OleDbDataAdapter("Select * From [SheetName$]",
excelConn)
       Dim escapeExit As Boolean = False
       Dim ds As DataSet = New DataSet()
       Dim dc As DataColumn = Nothing
       Dim dt As DataTable = Nothing
       Dim rec As String = ""
       Dim i As Integer = 0
       Dim x As Integer = 0
       da.Fill(ds)
       dt = excelConn.GetSchema

       Dim dr As DataRow
       While Not Me.bwWorker.CancellationPending
         'HERE'S THE PROBLEM: IT ALWAYS DECIDES THAT THERE'S 999
RECORDS!!!
           For Each dr In ds.Tables(0).Rows
               rec = ""
               For x = 0 To UBound(dr.ItemArray)
                   rec = rec & " " & dr.ItemArray(x).ToString
               Next
               logIt(txtOutput.Text & ControlChars.CrLf & rec)
               'Next
           Next
       End While
       excelConn.Close()
       excelConn.Dispose()

   End Sub
Douglas J. Steele - 22 Nov 2006 00:49 GMT
You'd probably have more luck asking in a newsgroup related to .Net.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)

> Hello!
> I'm using the code below to import an Excel datasheet into an ado.net
[quoted text clipped - 46 lines]
>
>    End Sub
brett.mack@gmail.com - 22 Nov 2006 13:45 GMT
Oops! SNAFU

> You'd probably have more luck asking in a newsgroup related to .Net.
>
[quoted text clipped - 53 lines]
> >
> >    End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.