G
Guest
I am currently using VS.NET 2005 to read in a text file into a sql server
database table. The code cycles through the file and using a .add with a
dataset seems to add all the rows just fine.
When the program finishes and I go do a query on the table it is empty. I
am new to using VS so I am wondering what I am missing. Below is the code I
use to load the test file. Any help would be greatly appreciated.
** Code Example
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim ai As Integer
Dim ls_array(1) As String
Dim maxfields As Integer = 0
If tablenm = "agCRT" Then
maxfields = 149
ReDim ls_array(149)
ElseIf tablenm = "agWRT" Then
maxfields = 71
ReDim ls_array(71)
End If
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentfield As String
Dim fieldnum As Integer = 0
ai = 0
For Each currentfield In currentRow
ls_array(ai) = currentfield
ai = ai + 1
If ai > maxfields Then
ds.Tables(tablenm).Rows.Add(ls_array)
End If
Next
Catch ex As
Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example
database table. The code cycles through the file and using a .add with a
dataset seems to add all the rows just fine.
When the program finishes and I go do a query on the table it is empty. I
am new to using VS so I am wondering what I am missing. Below is the code I
use to load the test file. Any help would be greatly appreciated.
** Code Example
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim ai As Integer
Dim ls_array(1) As String
Dim maxfields As Integer = 0
If tablenm = "agCRT" Then
maxfields = 149
ReDim ls_array(149)
ElseIf tablenm = "agWRT" Then
maxfields = 71
ReDim ls_array(71)
End If
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentfield As String
Dim fieldnum As Integer = 0
ai = 0
For Each currentfield In currentRow
ls_array(ai) = currentfield
ai = ai + 1
If ai > maxfields Then
ds.Tables(tablenm).Rows.Add(ls_array)
End If
Next
Catch ex As
Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example