
CARGAR TXT, EN UNA MATRIZ E INSERTAR LOS DATOS, EN DB ORACLE USANDO VB.NET
Publicado por janson (2 intervenciones) el 23/07/2015 05:17:44
buenas noches,
mi nombre es jason, y soy nuevo en vb.net, he estado mirando y buscando información, de como realizar esta labor,
la idea es seleccionar un archvo de txt y cargarlo en una matriz y asi cargarlo en una bd oracle
pero creo que no he entendido bien los conceptos, para aplicarlos de forma correcta, en la función, debido a esto acudo a ustedes, en busca de orientación o en su defecto me indiquen donde estoy errando,,, de antemano mil gracias, por la atención prestada
Public Sub prueba(ByVal ofd As OpenFileDialog, ByVal tabla As ListBox, ByVal delimitador As String)
Dim ruta As String = ""
'almecena las lineas de texto leida
Dim lineatexto As String = ""
'VECTOR ALMACENA LA LINEA Y LAS SEPARA, DELIMITADOR
Dim filas() As String
Dim columnas() As String
Dim matriz(,) As Object
ofd.InitialDirectory = "c:\temp\"
ofd.Filter = "txt files (*.txt)|*.txt" 'Formatos permitidos en objeto
ofd.FilterIndex = 2
ofd.Title = "SELECCIONE EL DOCUMENTO DE LAS ASIGNACIONES"
ofd.Multiselect = False
ofd.RestoreDirectory = True
If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
ruta = ofd.FileName
End If
'SI EXISTE EL ARCHIVO
If System.IO.File.Exists(ruta) = True Then
Dim VAR_LEER As New StreamReader(ruta)
Do While VAR_LEER.Peek <> -1
lineatexto = VAR_LEER.ReadLine()
filas = Split(lineatexto, vbCrLf)
columnas = Split(filas, delimitador)
ReDim matriz(0 To UBound(filas), UBound(columnas))
Dim i, j As Integer
For i = LBound(filas) To UBound(filas)
columnas(j) = Split(filas(i), delimitador)
For j = LBound(columnas) To UBound(columnas)
matriz(i, j) = columnas(j)
tabla.Items.Add(matriz(i, j))
Next j
Next i
Loop
Else
MsgBox("ARCHIVO NO EXISTE", MsgBoxStyle.Critical, "CSV NO EXISTE")
End If
End Sub
ese es la parte esencial de la funcion, agradezco su ayuda
mi nombre es jason, y soy nuevo en vb.net, he estado mirando y buscando información, de como realizar esta labor,
la idea es seleccionar un archvo de txt y cargarlo en una matriz y asi cargarlo en una bd oracle
pero creo que no he entendido bien los conceptos, para aplicarlos de forma correcta, en la función, debido a esto acudo a ustedes, en busca de orientación o en su defecto me indiquen donde estoy errando,,, de antemano mil gracias, por la atención prestada
Public Sub prueba(ByVal ofd As OpenFileDialog, ByVal tabla As ListBox, ByVal delimitador As String)
Dim ruta As String = ""
'almecena las lineas de texto leida
Dim lineatexto As String = ""
'VECTOR ALMACENA LA LINEA Y LAS SEPARA, DELIMITADOR
Dim filas() As String
Dim columnas() As String
Dim matriz(,) As Object
ofd.InitialDirectory = "c:\temp\"
ofd.Filter = "txt files (*.txt)|*.txt" 'Formatos permitidos en objeto
ofd.FilterIndex = 2
ofd.Title = "SELECCIONE EL DOCUMENTO DE LAS ASIGNACIONES"
ofd.Multiselect = False
ofd.RestoreDirectory = True
If (ofd.ShowDialog() = Windows.Forms.DialogResult.OK) Then
ruta = ofd.FileName
End If
'SI EXISTE EL ARCHIVO
If System.IO.File.Exists(ruta) = True Then
Dim VAR_LEER As New StreamReader(ruta)
Do While VAR_LEER.Peek <> -1
lineatexto = VAR_LEER.ReadLine()
filas = Split(lineatexto, vbCrLf)
columnas = Split(filas, delimitador)
ReDim matriz(0 To UBound(filas), UBound(columnas))
Dim i, j As Integer
For i = LBound(filas) To UBound(filas)
columnas(j) = Split(filas(i), delimitador)
For j = LBound(columnas) To UBound(columnas)
matriz(i, j) = columnas(j)
tabla.Items.Add(matriz(i, j))
Next j
Next i
Loop
Else
MsgBox("ARCHIVO NO EXISTE", MsgBoxStyle.Critical, "CSV NO EXISTE")
End If
End Sub
ese es la parte esencial de la funcion, agradezco su ayuda
Valora esta pregunta


0