
seleccionar varias filas de un grid y actualizarlas
Publicado por FERNANDO (1 intervención) el 03/11/2021 07:07:42
Buenas y un saludo a todos
por favor necesito de su amable ayuda para un problemita que tengo con visual 2019
estoy desarrollando una aplicacion en formato windows form, vb.net en capas en el formulario presentacion tengo un datagridview el cual lleno con una tabla sql alojada en azure, esta tabla se actualiza por medio de textboxes para las actualizaciones uso procedimientos almacenados, los procedimiento funcionan bien pero, necesito actualizar los registros de la tabla pero solo de las filas (filas, no columnas)que el usuario seleccione ej:
si la tabla tiene cien filas y de esas cien el usuario selecciona cinco (cuales quiera no importando el orden) solo se modifiquen,actualicen esas cinco, pero no lo consigo, mi conocimiento es casi nulo en vb y sql asi que si pudieran explicarmelo con "dibujitos" se los agradeceria mucho aqui los codigos
con este PA actualizo la tabla
en la capa que he llamado datos tengo este codigo
en la capa que he llamado logica tengo este codigo
y en el form presentacion tengo este codigo
el problema es que al seleccionar varias filas del datagridview solo me actualiza la ultima,como dato adicional en el evento CellContentClick del datagridview tengo este codigo, el cual me muestra los datos de las celdas en unos textboxes
he buscado por todo google y no encuentro una solucion, de antemano muchisimas gracias y como les explique por favor si no es mucho pedir, no usen lenguaje muy tecnico pues mi conocimiento es casi nulo
por favor necesito de su amable ayuda para un problemita que tengo con visual 2019
estoy desarrollando una aplicacion en formato windows form, vb.net en capas en el formulario presentacion tengo un datagridview el cual lleno con una tabla sql alojada en azure, esta tabla se actualiza por medio de textboxes para las actualizaciones uso procedimientos almacenados, los procedimiento funcionan bien pero, necesito actualizar los registros de la tabla pero solo de las filas (filas, no columnas)que el usuario seleccione ej:
si la tabla tiene cien filas y de esas cien el usuario selecciona cinco (cuales quiera no importando el orden) solo se modifiquen,actualicen esas cinco, pero no lo consigo, mi conocimiento es casi nulo en vb y sql asi que si pudieran explicarmelo con "dibujitos" se los agradeceria mucho aqui los codigos
con este PA actualizo la tabla
1
2
3
4
5
6
7
8
9
10
11
CREATE PROCEDURE PAGADO
(
@COMENTARIOS VARCHAR (50),
@PAGADO VARCHAR (50)NULL,
@FECHA_PAGADO DATE NULL,
@MODIFICADO_POR VARCHAR (50)NULL
)
AS
UPDATE tclientes2
SET COMENTARIOS = @COMENTARIOS,PAGADO = @PAGADO,FECHA_PAGADO=@FECHA_PAGADO,MODIFICADO_POR=@MODIFICADO_POR
WHERE RETIRADO = @RETIRADO
en la capa que he llamado datos tengo este codigo
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
Public Shared Function pagado_remu(ByVal COMENTARIOS As String, ByVal PAGADO As String, ByVal FECHA_PAGADO As Date, ByVal MODIFICADO_POR As String) As String
Dim oconex15 As New SqlConnection("Data Source=dcencomiendas.database.windows.net;Initial Catalog=CLIENTES;User ID=********;Password="*********")
oconex15.Open()
Dim rpta As Boolean = False
Dim filaseditadas As Int16
Dim comand As New SqlCommand
comand.Connection = oconex15
comand.CommandType = CommandType.StoredProcedure
comand.CommandText = "PAGADO"
comand.Parameters.AddWithValue("@COMENTARIOS", COMENTARIOS)
comand.Parameters.AddWithValue("@PAGADO", PAGADO)
comand.Parameters.AddWithValue("@FECHA_PAGADO", FECHA_PAGADO)
comand.Parameters.AddWithValue("@MODIFICADO_POR", MODIFICADO_POR)
filaseditadas = comand.ExecuteNonQuery
oconex15.Close()
If filaseditadas > 0 Then
rpta = True
End If
Return rpta
End Function
en la capa que he llamado logica tengo este codigo
1
2
3
Public Shared Function pagado_remu(ByVal COMENTARIOS As String, ByVal PAGADO As String, ByVal FECHA_PAGADO As Date, ByVal MODIFICADO_POR As String) As String
Return datos.clientedatos.pagado_remu(COMENTARIOS, PAGADO, FECHA_PAGADO, MODIFICADO_POR)
End Function
y en el form presentacion tengo este codigo
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
73
74
75
76
77
Private Sub bt_pagar_Click(sender As Object, e As EventArgs) Handles bt_pagar.Click
Dim rpta As Boolean = False
Dim abrir As New REMUNERACIONES
abrir.tipo = "EDITAR"
Dim Id As Integer = dgvremus.CurrentRow.Cells(0).Value
If abrir._tipo = "EDITAR" Then
odt = logica.clientelogica.mostrar_tabla
dgvremus.DataSource = odt
indice = BindingContext(odt)
For Each row As DataGridViewRow In dgvremus.SelectedRows
Dim pago As String
If row IsNot DBNull.Value And row.Selected = True Then
pago = logica.clientelogica.pagado_remu(tx_comentariosremu.Text, cb_formapago.Text, date_pagado.Value, usuarioactivo.USUARIO)
_tipo = ""
odt = logica.clientelogica.mostrar_tabla
dgvremus.DataSource = odt
If rb_filtro_fecharetirado.Checked = True Then
dgvremus.DataSource = logica.clientelogica.filtrar_fechas_remus(date_fechaini_buscar_remu.Value.ToString, date_fechafin_buscar_remu.Value.ToString)
Dim total As Single
For Each fila As DataGridViewRow In dgvremus.Rows
If fila.Cells(11) IsNot DBNull.Value.ToString And fila.Cells(11).Value.ToString = "SI" Then
total += fila.Cells(15).Value
End If
Next
tx_totalpago.Text = Format(total, " $ ##,###0.00")
Else
If rb_filtrarfecha.Checked = True Then
dgvremus.DataSource = logica.clientelogica.buscar_remus(date_fechaini_buscar_remu.Value.ToString, date_fechafin_buscar_remu.Value.ToString)
Dim total As Single
For Each fila As DataGridViewRow In dgvremus.Rows
If fila.Cells(11) IsNot DBNull.Value.ToString And fila.Cells(11).Value.ToString = "SI" Then
total += fila.Cells(15).Value
End If
Next
tx_totalpago.Text = Format(total, " $ ##,###0.00")
Else
If rb_filtrarfecha.Checked = True Then
dgvremus.DataSource = logica.clientelogica.buscar_remus(date_fechaini_buscar_remu.Value.ToString, date_fechafin_buscar_remu.Value.ToString)
Dim total As Single
For Each fila As DataGridViewRow In dgvremus.Rows
If fila.Cells(11) IsNot DBNull.Value.ToString And fila.Cells(11).Value.ToString = "SI" Then
total += fila.Cells(15).Value
End If
Next
tx_totalpago.Text = Format(total, " $ ##,###0.00")
Else
If rb_filtroavanzado.Checked = True Then
dgvremus.DataSource = logica.clientelogica.filtrar_fecha_vendedor_cliente(date_fechaavanzada.Value.ToString, tx_vendedoravanzado.Text, tx_clienteavanzado.Text)
Dim total As Single
For Each fila As DataGridViewRow In dgvremus.Rows
If fila.Cells(11) IsNot DBNull.Value.ToString And fila.Cells(11).Value.ToString = "SI" Then
total += fila.Cells(15).Value
End If
Next
tx_totalpago.Text = Format(total, " $ ##,###0.00")
End If
For i = 0 To dgvremus.Rows.Count - 1
If Id = dgvremus.Rows(i).Cells(0).Value Then
dgvremus.CurrentCell = dgvremus.Rows(i).Cells(1)
End If
Next
End If
End If
End If
End If
Next
MsgBox("*** HECHO ***")
tx_comentariosremu.Enabled = False
End If
indice = BindingContext(odt)
el problema es que al seleccionar varias filas del datagridview solo me actualiza la ultima,como dato adicional en el evento CellContentClick del datagridview tengo este codigo, el cual me muestra los datos de las celdas en unos textboxes
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
Public Sub dgvremus_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvremus.CellContentClick
tx_idremu.Text = dgvremus.CurrentRow.Cells(0).Value.ToString
tx_montooriginal.Text = dgvremus.CurrentRow.Cells(15).Value.ToString
tx_descuento.Text = dgvremus.CurrentRow.Cells(13).Value.ToString
tx_agregado.Text = dgvremus.CurrentRow.Cells(14).Value.ToString
tx_subtotal.Text = dgvremus.CurrentRow.Cells(10).Value.ToString
tx_totalpago.Text = dgvremus.CurrentRow.Cells(15).Value.ToString
rb_modmonto.Enabled = True
rb_sumarmonto.Enabled = True
Dim total As Single
For Each row As DataGridViewRow In dgvremus.SelectedRows
If row.Cells(1) IsNot DBNull.Value Then
total += row.Cells(15).Value '
End If
Next
tx_totalpago.Text = Format(total, " $ ##,###0.00")
Dim total2 As Single
For Each row2 As DataGridViewRow In dgvremus.SelectedRows
If row2.Cells(1) IsNot DBNull.Value Then
total2 += row2.Cells(10).Value
End If
Next
tx_subtotal.Text = Format(total2, " $ ##,###0.00")
Dim total4 As Single
For Each row4 As DataGridViewRow In dgvremus.SelectedRows
If row4.Cells(1) IsNot DBNull.Value Then
total4 += row4.Cells(13).Value
End If
Next
tx_descuento.Text = Format(total4, " $ ##,###0.00")
Dim total3 As Single
For Each row3 As DataGridViewRow In dgvremus.SelectedRows
If row3.Cells(1) IsNot DBNull.Value Then
total3 += row3.Cells(14).Value
End If
Next
tx_agregado.Text = Format(total3, " $ ##,###0.00")
End Sub
he buscado por todo google y no encuentro una solucion, de antemano muchisimas gracias y como les explique por favor si no es mucho pedir, no usen lenguaje muy tecnico pues mi conocimiento es casi nulo
Valora esta pregunta


0