Hi programmers out there, I have a windows form with three textboxes namely
Id, name,age . I also added a gridview to the form and its bound to the database.
I also added three buttons one for insert, delete and update records. Insert is done through the textboxes, upon a click of button am able to see what I have added in gridview. Am also able to delete upon a click of a button.
The code for update which is not working, no error message;
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Drawing
Imports System.Collections.Generic
Imports System.ComponentModel
Public Class sss
Inherits System.Windows.Forms.Form
Dim con As OleDbConnection = Nothing
Dim ds As DataSet
Dim cmd As OleDbCommand = Nothing
Dim dt As New DataTable
Dim cs As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DB.accdb;Persist Security Info=False;"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ID, FName, Age As String
ID = Txtid.Text
FName = txtfullname.Text
Age = txtAge.Text
Dim con As New OleDbConnection(cs)
Dim cmd As New OleDbCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "Update ssss SET FName=@FName,Age=@Age WHERE ID=@ID"
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@ID", ID)
cmd.Parameters.AddWithValue("@FName", FName)
cmd.Parameters.AddWithValue("@Age", Age)
cmd.ExecuteNonQuery()
MessageBox.Show("updated......")
con.Close()
Binder()
End Sub
Private Sub Binder()
Dim con As New OleDbConnection(cs)
Dim cmd As New OleDbCommand()
cmd.Connection = con
con.Open()
Dim da As New OleDbDataAdapter("select * from ssss", con)
Dim dt As New DataTable()
da.Fill(dt)
DataGridView1.DataSource = dt
con.Close()
End Sub