Visual Basic.NET - el indice esta fuera del intervalo

 
Vista:
sin imagen de perfil

el indice esta fuera del intervalo

Publicado por damian (1 intervención) el 02/08/2014 16:59:32
Me sale este error :

Hago una consulta para traer datos a un datagrid y me tira el error :el indice esta fuera del intervalo,debe ser un valor no negativo e inferior al tamaño de la coleccion.Le doy aceptar y me trae igual los datos y no pudo sacar ese cartel con ese error



Try

Dim comando1 As New MySqlCommand

comando1.Connection = conn
comando1.CommandType = CommandType.StoredProcedure
comando1.CommandText = "TraePeCotizacion"
comando1.Parameters.Add(New MySqlParameter("@ParamId", (cmbpedcot.SelectedValue)))

Dim dr1 As MySqlDataReader
dr1 = comando1.ExecuteReader()

Dim tabla1 As New DataTable
tabla1.Dispose()
tabla1.Load(dr1)

Dim idproveedor As Integer
Dim preap As Integer
Dim fecha As String
' Dim fechaformato As String


idproveedor = tabla1.Rows(0).Item(2).ToString
'txtlugar.Text = tabla1.Rows(0).Item(5).ToString
fecha = tabla1.Rows(0).Item(7).ToString
preap = tabla1.Rows(0).Item(4).ToString

'fechaformato = Format(CDate(fecha), "yyyy/MM/dd")
'txtfechaentrega.Text = fechaformato


Dim comando2 As New MySqlCommand
comando2.Connection = conn
comando2.CommandType = CommandType.StoredProcedure

comando2.CommandText = "TraeRazonSocial"
comando2.Parameters.Add(New MySqlParameter("@ParamIdProveedor", idproveedor))

Dim dr2 As MySqlDataReader
dr2 = comando2.ExecuteReader()

Dim tabla2 As New DataTable
tabla2.Dispose()
tabla2.Load(dr2)

'txtproveedor.Text = tabla2.Rows(0).Item(0).ToString "no va mepa"

Dim comando3 As New MySqlCommand

comando3.Connection = conn
comando3.CommandType = CommandType.StoredProcedure
comando3.CommandText = "TraeProductosPorProveedor"
comando3.Parameters.Add(New MySqlParameter("@ParamProveedor", idproveedor))
comando3.Parameters.Add(New MySqlParameter("@ParamPedido", preap))

Dim dr3 As MySqlDataReader
dr3 = comando3.ExecuteReader()

Dim tabla3 As New DataTable
tabla3.Dispose()
tabla3.Load(dr3)

DataGridView1.DataSource = tabla3


Catch exmysql As MySqlException
MessageBox.Show("Error: " & exmysql.Message)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)

End Try
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 giancarlo
Val: 377
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

el indice esta fuera del intervalo

Publicado por giancarlo (488 intervenciones) el 06/08/2014 17:43:31
yo nunca intente con eso de tabla1.Load(dr1), pero si funciona bien.

cuando usas el DataReader, requieres abrir una conexion, seria algo asi

dim fila as datarow
Try
cn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
while dr.Read()
fila =tabla.newrow'si no sale debe ser algo como tabla.rows.newrow
fila(0)= CInt(dr("codcli"))
fila(1)= dr("nombre").ToString
tabla.rows.add(fila)
end while
dr.close
catch ex as exception
msgbox(ex.tostring)
finally
if cn.connectionstate=open
cn.close
end if
end try

el ejemplo es en SQL, pero para ODBC,OLDB y mysql... solo cambias el SQL por mysql
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