http://pabletoreto.blogspot.com/2012/01/vb-y-access.html
con lo anterior el form queda modificado desde la primera entrega vista en el link anterior de la siguiente manera:
ahora agregamos un modulo al proyecto, dando click derecho sobre este en el Solution Explorer, seleccionamos Add y luego Module
aquí ponemos nombre al module, yo le deje el nombre por defecto osea Module1.vb
mports System.Data
Imports System.Data.OleDb
Module Module1
Public cnn As New OleDbConnection(My.Settings.yo)
Dim dt As DataTable
Dim oda As OleDbDataAdapter
Dim cmd As OleDbCommand
Public Function CargarDatos() As DataTable
Try
Using oda = New OleDbDataAdapter("select * from imagen", cnn)
dt = New DataTable
oda.Fill(dt)
End Using
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return dt
End Function
Public Sub ModificarDatos(ByVal val1, ByVal val2, ByVal val3, ByVal val4)
Dim sql As String = "Update imagen set nombre_foto= '" & val1 & "', comentarios= '" & val2 & "', ruta_foto= '" & val3 & "' where id= '" & val4 & "'"
Try
cnn.Open()
cmd = New OleDbCommand
cmd.Connection = cnn
cmd.CommandText = "update imagen SET nombre_foto = @nfoto, comentarios=@com, ruta_foto=@rfoto where id = @id"
cmd.Parameters.AddWithValue("@nfoto", val1)
cmd.Parameters.AddWithValue("@com", val2)
cmd.Parameters.AddWithValue("@rfoto", val3)
cmd.Parameters.AddWithValue("@cid", val4)
cmd.ExecuteNonQuery()
MessageBox.Show("Dato modificado satisfactoriamente")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn.Close()
'Y por último, ya dentro del bloque finally cerraremos la conexión y liberaremos el Garbage Collector para nuestro comando.
cmd.Dispose()
End Try
End Sub
Public Sub EliminarDatos(ByVal val1)
Try
cnn.Open()
cmd = New OleDbCommand
cmd.Connection = cnn
cmd.CommandText = "delete from imagen where id = @id"
cmd.Parameters.AddWithValue("@cid", val1)
cmd.ExecuteNonQuery()
MessageBox.Show("Dato eliminado satisfactoriamente")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn.Close()
cmd.Dispose()
End Try
End Sub
Public Sub IngresarDatos(ByVal val1, ByVal val2, ByVal val3)
Try
cnn.Open()
cmd = New OleDbCommand
cmd.Connection = cnn
cmd.CommandText = "insert into imagen(nombre_foto, comentarios, ruta_foto) values (@nfoto, @com, @rfoto)"
cmd.Parameters.AddWithValue("@nfoto", val1)
cmd.Parameters.AddWithValue("@com", val2)
cmd.Parameters.AddWithValue("@rfoto", val3)
cmd.ExecuteNonQuery()
MessageBox.Show("Datos ingresados satisfactoriamente")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
cnn.Close()
cmd.Dispose()
End Try
End Sub
End Module
Imports System.Data.OleDb
Imports System.Data
Public Class Form1
Dim bs As New BindingSource
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mostrando()
End Sub
Private Sub mostrando()
Try
bs.DataSource = CargarDatos()
BindingNavigator1.BindingSource = bs
DataGridView1.DataSource = bs
TextBox1.DataBindings.Clear()
TextBox2.DataBindings.Clear()
TextBox3.DataBindings.Clear()
TextBox4.DataBindings.Clear()
TextBox1.DataBindings.Add("text", bs, "nombre_foto")
TextBox2.DataBindings.Add("text", bs, "comentarios")
TextBox3.DataBindings.Add("text", bs, "ruta_foto")
TextBox4.DataBindings.Add("text", bs, "Id")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub Ingresar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Ingresar.Click
IngresarDatos(TextBox1.Text, TextBox2.Text, TextBox3.Text)
mostrando()
End Sub
Private Sub Bmodificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmodificar.Click
ModificarDatos(TextBox1.Text, TextBox2.Text, TextBox3.Text, TextBox4.Text)
mostrando()
End Sub
Private Sub Beliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Beliminar.Click
EliminarDatos(TextBox4.Text)
mostrando()
End Sub
End Class
Compilamos, ejecutamos y ya