Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/08/2013, 14:01
lordbeliar2010
 
Fecha de Ingreso: junio-2013
Mensajes: 18
Antigüedad: 10 años, 10 meses
Puntos: 0
como actulizar bd desde un datagrivie no enlazado a una bd?

Saludos a todos mi duda es la siguiente

tengo un datagridview que no esta enlazado a ninguna tabla de la bd pero si qiero que el contenido que yo agrego manuelmente al datagridview,actualice campos ya existente en una de las tablas de la BD

LES EXPLICO COMO REALIZO EL PRECESO
1- BUSCO EL PRODUCTO SI LO ENCUNETRA RELLENA TODOS LOS CAMPOS TEXTBOX
2-HAGO LOS CAMBIOS QUE VOY A REALIZAR EN LOS TEXTBOX
3-AGREGO ESE PRODUCTO AL DATAGRIDVIEW CON SUS CAMBIO QUE REALICE ANTERIORMENTE CON UN BOTON LLAMADO "AGREGAR"
LOS CAMPOS QUE SE AGREGAN AL DATAGRIDVIEW SON LOS SIGUIENTES
CODPRODUCTO PCOMPRA PVENTA ENTRADA EXISTENCIA
PERO SOLAMENTO PCOMPRA PVENTA ENTRADA EXISTENCIA VOY ACTUALIZAR EN MI TABLA PRODUCTO

4-Y VUELVO A REPETIR EL PROCESO AGREGANDO OTRO PRODCUTO AL DATAGRIDVIEW

AHORA LES MUESTRO EL CODIGO EN VBNET COMO LO TENGO Q NO ME FUNCIONA

RECUERDEN QUE TODO ESTO LO REALIZO EN VBNET

TAMBIEN QUE EN EL DATAGRID PUEDN AVER MAS DE UN PRODUCTO
Código PHP:
    Public Sub update_con_txtfindnomprod()
        
Dim query As String "update producto set pc=@pc, pv=@pv, entrada=@entrada, existencia=@existencia where cod_producto=@codprod "
        
Dim lsqlcomand As New SqlCommand(querycnx)

        If 
Me.txtnfactura.Text <> "" And Me.txtcodprod.Text <> "" And Me.txtpc.Text <> "" And Me.txtpv.Text <> "" And Me.txtentrada.Text <> "" And Me.txtexist.Text <> "" Then

            cnx
.Open()
            Try
                For 
Each row As DataGridViewRow In DataGridView1.Rows
                    lsqlcomand
.Parameters.Clear()
                    
lsqlcomand.Parameters.AddWithValue("@pc"Convert.ToDouble(row.Cells("pc").Value))
                    
lsqlcomand.Parameters.AddWithValue("@pv"Convert.ToDouble(row.Cells("pv").Value))
                    
lsqlcomand.Parameters.AddWithValue("@entrada"Convert.ToString(row.Cells("entrada").Value))
                    
lsqlcomand.Parameters.AddWithValue("@existencia"Convert.ToString(row.Cells("existencia").Value))
                
Next
                lsqlcomand
.ExecuteNonQuery()
                
cnx.Close()
                
MessageBox.Show("Actualizacion Realizada Correctamente"".::::."MessageBoxButtons.OK)
            Catch 
ex As Exception
                MsgBox
(ex.Message)
            
End Try

        Else
            
MessageBox.Show("Debe de llenar todos los campos"".::::."MessageBoxButtons.OK)
        
End If
    
End Sub 
YA PUEDO ACTUALIZAR HE ARREGLADO EL CODIGO PERO SE ACTUALIZAN TODO LOS PRODUCTO CON LA MISMA INFORMACION
AUQI ESTA EL CODIGO
Código PHP:
Public Sub update_con_txtfindnomprod()
        
Dim query As String "update producto set pc=@pc, pv=@pv, entrada=@entrada, existencia=@existencia"
        
Dim lsqlcomand As New SqlCommand(querycnx)

        
cnx.Open()
        Try
            
With lsqlcomand
                
For Each row As DataGridViewRow In DataGridView1.Rows
                    lsqlcomand
.Parameters.Clear()
                    
lsqlcomand.Parameters.AddWithValue("@pc"CStr(row.Cells("pc").Value))
                    
lsqlcomand.Parameters.AddWithValue("@pv"CStr(row.Cells("pv").Value))
                    
lsqlcomand.Parameters.AddWithValue("@entrada"CStr(row.Cells("entrada").Value))
                    
lsqlcomand.Parameters.AddWithValue("@existencia"CStr(row.Cells("exist").Value))
                
Next
            End With
            lsqlcomand
.ExecuteNonQuery()
            
cnx.Close()
            
MessageBox.Show("Actualizacion Realizada Correctamente"".::::."MessageBoxButtons.OK)
        Catch 
ex As Exception
            MsgBox
(ex.Message)
        
End Try
  
End Sub 

Última edición por lordbeliar2010; 27/08/2013 a las 17:29