Visual Basic - IndexOutOfRangeException : No hay ninguna fila en la posición 0

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

IndexOutOfRangeException : No hay ninguna fila en la posición 0

Publicado por aline (1 intervención) el 26/05/2017 20:14:51
HOLA, ESTOY HACIENDO UNA APLICACIÓN EN VISUAL BASIC EN DONDE DESEO CARGAR UN ARCHIVO .TXT Y QUE SE GUARDEN EN UNA BASE DE DATOS DE SQL, MI PROBLEMA ES QUE AL EJECUTAR ME MARCA EL SIGUIENTE ERROR:
IndexOutOfRangeException was unhandled: No hay ninguuna fiila en la posicion 0
ALGUIEN QUE PUEDA ASESORARME, DE ANTE MANO GRACIAS :)
-----------------------------------------------------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Private Sub carga_button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carga_button.Click
    Dim Matriz(100, 6) As String
    ' Pide ruta del archivo
    Dim archivo As New OpenFileDialog()
    Dim ruta As String = ""
    archivo.Filter = "Txt|*.txt"
    archivo.Title = "Abrir"
 
    ' Guarda ruta del archivo
    If archivo.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
        ruta = archivo.FileName.ToString()
    End If
 
    Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(ruta)
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        ' Indica con que simbolo termina cada dato
        MyReader.SetDelimiters(";")
        Dim lineaActual As String()
        Dim i As Integer = 0
 
        While Not MyReader.EndOfData
            Try
                lineaActual = MyReader.ReadFields()
                Dim datoActual As String
                Dim j As Integer = 0
                For Each datoActual In lineaActual
                    ' Guarda el registro en la matriz
                    Matriz(i, j) = datoActual
                    j += 1
                    If j >= 6 Then
                        j = 0
                        i += 1
                    End If
                Next
            Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
            End Try
        End While
    End Using
    Dim registros As Integer = 0
    Dim noAgregados As String = ""
    ' Se insertan a la base de datos
 
    ConsultaSql = "Select * From gasolina"
    dsResultado = o_gasolina.ConsultasGasolina("select * from gasolina where fecha = (select MAX(fecha) from gasolina)")
    dsResultado = o_gasolina.ConsultasGasolina(ConsultaSql)
 
AQUI ME MARCA EL ERROR:
 
>>> vehiculo_textbox.Text = dsResultado.Tables("gasolina").Rows(0).Item("vehiculo")
    proveedor_textbox.Text = dsResultado.Tables("gasolina").Rows(0).Item("proveedor")
    kilometraje_textbox.Text = dsResultado.Tables("gasolina").Rows(0).Item("kilometraje")
    carga_textbox.Text = dsResultado.Tables("gasolina").Rows(0).Item("litros")
    monto_textbox.Text = dsResultado.Tables("gasolina").Rows(0).Item("monto")
    fecha_date.Text = dsResultado.Tables("gasolina").Rows(0).Item("fecha")
 
    ' Se pasan a la base de datos los registros de la matriz
    For i As Integer = 0 To 100
        If Matriz(i, 0) <> "" Then
            registros += registros
            ConsultaSql = "Insert Into CargaGasolina (id_carga, proveedor, kilometractual, litros, monto, fecha, rendimiento, kilometraje) " & _
                "Values ('" & Matriz(i, 0) & "', '" & Matriz(i, 1) & "', '" & _
                Matriz(i, 2) & "', '" & Matriz(i, 3) & "', '" & Matriz(i, 4) & "', '" & Matriz(i, 5) & "')"
            If o_gasolina.insertar(ConsultaSql) = False Then
                noAgregados = noAgregados & Matriz(i, 0) & ", "
            End If
        End If
 
    Next
 
    MsgBox("Se intentaron agregar " & registros & " registros. ")
    MsgBox("No se pudieron agregar: " & noAgregados)
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Antoni Masana
Val: 1.259
Plata
Ha mantenido su posición en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

IndexOutOfRangeException : No hay ninguna fila en la posición 0

Publicado por Antoni Masana (558 intervenciones) el 29/05/2017 08:06:44
¿Existe la fila 0?
¿Existe la columna 0?

¿Cual es la Rows(0)?

Si no existen porque intentas asignar un valor a la celda 0.

Saludos.
\\//_
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar