wessir
asked on
Dataset does not return 1st row?
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?
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
ASKER
I don't know if it's not returning all or if the dataset isn't filled properly. dsDataSet.Tables(0).Rows.C ount 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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is the dsDataSet.Tables(0).Rows.C