Quantcast
Channel: RECORRER UN DATAGRID VB.NET
Viewing all articles
Browse latest Browse all 5

RECORRER UN DATAGRID VB.NET

$
0
0

Hola:
Prueba a cambiar tu codigo por este.
Este ejemplo es para SQL Server, tienes que cambiar para MySql, SqlDataReader por MySqlDataReader, SqlCommand por MySqlCommand etc


    Private Sub validar_productos()
        Dim egre As Integer
        Dim sql As String = String.Empty
        Try
            Using loConexion As New SqlConnection("TU_CADENA_DE_CONEXION")
                loConexion.Open()
                For Each fila As DataGridViewRow In dtg_ventas.Rows
                    sql = "Select CANTIDAD From tbl_productos WhereCODIGO=@Codigo"
                    Using loComando As New SqlCommand(sql, loConexion)
                        loComando.Parameters.Add(New SqlParameter("@Codigo", fila.Cells("CODIGO").Value))
                        Using loDataReader As SqlDataReader = loComando.ExecuteReader()
                            Do While loDataReader.Read()
                                egre = CInt(loDataReader("CANTIDAD")) - CInt(fila.Cells("CANTIDAD").Value) '// ACA SE LE RESTA A LA CANTIDAD EN EL INTARIO LO QUE SE VA COMPRAR
                            Loop
                        End Using
                    End Using
                    sql = "Update tbl_productos SetCANTIDAD=@Cantidad Where CODIGO=@Codigo"
                    Using loComando As New SqlCommand(sql, loConexion)
                        loComando.Parameters.Add(New SqlParameter("@Cantidad", egre))
                        loComando.Parameters.Add(New SqlParameter("@Codigo", fila.Cells("CODIGO").Value))
                        loComando.ExecuteNonQuery()
                    End Using
                Next
            End Using
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error restar cantidades")
        End Try
    End Sub

Un saludo desde Bilbo
Carlos


Viewing all articles
Browse latest Browse all 5


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>