Estimados hice lo siguiente para leer un archivo de texto con 2 columnas e insertarlas en una tabla..lo hace pero no me convence quizas halla algo mas simple.
Try
Dim lector As TextFieldParser
Dim linea As String()
Dim bandera As Integer
bandera = 1
Dim campo As String
lector = New TextFieldParser("d:codigos.txt")
lector.TextFieldType = FieldType.Delimited
lector.SetDelimiters(",")
While Not lector.EndOfData
Try
linea = lector.ReadFields()
While Not lector.EndOfData
Try
linea = lector.ReadFields()
For Each campo In linea
If bandera = 1 Then
Dim variable As String = "INSERT INTO pre_inventario(codigo)VALUES('" + campo + "')"
Dim insertar As New OleDbCommand(variable, cnn)
cnn.Open()
insertar.ExecuteNonQuery()
cnn.Close()
bandera = 2
paso = campo
ElseIf bandera = 2 Then
Dim variable As String = "UPDATE pre_inventario SET cantidad= " + campo + " WHERE codigo='" + paso + "'"
Dim insertar As New OleDbCommand(variable, cnn)
cnn.Open()
insertar.ExecuteNonQuery()
cnn.Close()
bandera = 1
End If
Next
Catch ex As MalformedLineException
MsgBox("Linea " & ex.Message)
End Try
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End While