VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello everyone.
I have a datagridview, designed with two specific columns.
with this code I try to fill the columns, predesigned
Try
Using Conexion As New SqlConnection(cadenaconexion)
Conexion.Open()
Dim consultaSQL As String = "Select CodigoProducto, DescripcionProducto from TblaDetalleFactura2 WHERE CodigoFactura =@CodigoFactura"
Dim comando As New SqlCommand(consultaSQL, Conexion)
comando.Parameters.AddWithValue("@CodigoFactura", txtCodigoFactura.Text)
'LD=LectorDatos
Dim LD As SqlDataReader
LD = comando.ExecuteReader()
If LD.Read() Then
Dim CodigoProductoEncontrado As String
Dim DescripcionProductoEncontrado As String
'Establecemos valores de la asignación, en el mismo orden de los valores de la consulta
CodigoProductoEncontrado = LD.GetInt64(LD.GetOrdinal("CodigoProducto"))
DescripcionProductoEncontrado = LD.GetString(LD.GetOrdinal("DescripcionProducto"))
DGVDetalle_Factura.Rows.Add(CodigoProductoEncontrado, DescripcionProductoEncontrado)
End If
End Using
Catch ex As Exception
MsgBox("Error al intentar Cargar los Datos de los Controles",
vbExclamation, "Error")
MessageBox.Show(ex.Message) ' Muestra el Mensaje de Error.
End Try
The problem is that the Code only fills one row of the datagridview
But according to the information in the table, it should have turned out like this:
I hope you can help me, thanks in advance.
this part
If LD.Read() Then
......
End If
Change like this
While LD.Read()
......
End While
Solved 100x%
Thank you….