Me conecto a una tabla de visual fox, creo el dataadapter y una variable para el command
filtro a travez de un datable los datos a un datagridview(con la Funcion carga_tb_kardex)en el evento del load form, en datagridview slecciono una celda de tipo double al momento de finalizar la edición deberia guardar los cambios en la tabla
Imports System.Data.Odbc
Public Class Conectar
Private conn As New OdbcConnection("DSN=Conectar;Persist Security Info=False")
Public datadapt_tbkardex As New OdbcDataAdapter("select codmod, cargo, apepater, apemater, nombre, nombres, monto, dtoc(f_inicre) as f_inicre from kardex order by apepater, apemater, nombre", conn)
Public sqlcomando As New OdbcCommand("UPDATE karde SET monto = @monto WHERE codmod = @codmod", conn)
Public datab_tbkardex As New DataTable
Public Sub Conectar()
Try
conn.Open()
Catch ex As Exception
MsgBox("No se logrop realizar la conexion debido a : ", MsgBoxStyle.Information, "Program para Generar Arcivo de texto")
End Try
End Sub
Public Sub operaciones(ByVal numericValue As Double, ByVal idValue As String)
sqlcomando.Parameters.AddWithValue("@monto", OdbcType.Double).Value = numericValue
sqlcomando.Parameters.AddWithValue("@codmod", OdbcType.Char).Value = idValue
datadapt_tbkardex.UpdateCommand = sqlcomando
End Sub
Public Function Carga_tb_kardex() As DataTable
datadapt_tbkardex.Fill(datab_tbkardex)
conn.Close()
Return datab_tbkardex
End Function
End Class
enter image description here
esperba que al momento de terminar la edición se actualizara en la base de datos este el codigo que empleo en el datagridview
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
If e.ColumnIndex = DataGridView1.Columns("monto").Index Then
classconex.Conectar()
Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
Dim numericValue As Double = CType(row.Cells("monto").Value, Double)
Dim idValue As String = CType(row.Cells("codmod").Value, String)
classconex.operaciones(numericValue, idValue)
End If
End Sub
Renee Tafur Pino is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.