Solved

Dataset does not return 1st row?

Posted on 2009-07-14
3
202 Views
Last Modified: 2012-05-07
This might be easy but...
I've opened a CSV file using ADO, filled a DataSet from the result but I'm not getting the first row. Is this a 0 based thing?
cn = New ADODB.Connection
        cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                "Data Source=" & strInputFilePath & ";" & _
                "Extended Properties='text;HDR=NO;FMT=Delimited'")
        'create a new recordset
        rsSource = New ADODB.Recordset
        rsSource.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        rsSource.CursorType = ADODB.CursorTypeEnum.adOpenStatic
        rsSource.LockType = ADODB.LockTypeEnum.adLockBatchOptimistic
        rsSource.Open("SELECT * FROM [" & System.IO.Path.GetFileName(strInputFile) & "]", cn)
        rsSource.ActiveConnection = Nothing
        cn.Close()
 
        Dim daDataAdapter As New System.Data.OleDb.OleDbDataAdapter()
        Dim dsDataSet As New DataSet()
        Dim drRow As DataRow
        daDataAdapter.Fill(dsDataSet, rsSource, System.IO.Path.GetFileName(strInputFile))
        
        Dim lngMaxRows As Long = dsDataSet.Tables(0).Rows.Count
        Dim sw As StreamWriter
        Dim dcColumn As DataColumn
       
        sw = New StreamWriter(strOutputFile)
        'Loop through Input file dataset
        For Each drRow In dsDataSet.Tables(0).Rows
 
            For Each dcColumn In dsDataSet.Tables(0).Columns
                If dcColumn.ColumnName.ToString = "SEQ_NO" Then
                    'format this field
                    str = str & drRow("SEQ_NO").ToString("00000000")
                Else
                    str = str & drRow(dcColumn.ColumnName) & Chr(9)
                End If
            Next
            sw.WriteLine(str)
        Next

Open in new window

0
Comment
Question by:wessir
[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
  • 2
3 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 24854150
Do you mean your query itself is not returning the first row?
Is the dsDataSet.Tables(0).Rows.Count returning right count?

0
 

Author Comment

by:wessir
ID: 24854546
I don't know if it's not returning all or if the dataset isn't filled properly.  dsDataSet.Tables(0).Rows.Count returns 999 instead of the 1,000 records in the original CSV file.  The output file is missing the first record so it seems the 999 count is correct.
0
 

Accepted Solution

by:
wessir earned 0 total points
ID: 24854589
I added the following line to my Schema.ini file and that took care of it...
ColNameHeader=False
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

635 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