Hi, I am trying to delete data from dataGridview, and update my Access database, but I am having trouble withe these code it keep stated that I have "Object not set to an instance of an object" and I don't know where my code went wrong, please help, I am desperate...thanks you
Here are my code:
Dim con As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=Individual.mdb")
Dim btnDelete As Windows.Forms.DataGridViewButtonColumn
Dim MaxRows As New Integer
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim inc As New Integer
Private Sub GridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles GridView1.CellContentClick
Try
If GridView1.Columns(e.ColumnIndex).Name = "Delete" AndAlso Me.GridView1.Rows(e.RowIndex).IsNewRow = False Then
'i = GridView1.CurrentRow.Index
'table.Rows(i).Delete()
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("AddressBook").Rows(inc).Delete()
MaxRows = MaxRows - 1
inc = 0
da.Update(ds, "AddressBook")
Me.GridView1.EndEdit()
Me.GridView1.Rows.RemoveAt(e.RowIndex)
da.Update(ds, "AddressBook")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub IndiAdd3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim btn As New DataGridViewButtonColumn()
GridView1.Columns.Add(btn)
btn.HeaderText = "Delete"
btn.Text = "Delete"
btn.Name = "Delete"
btn.UseColumnTextForButtonValue = True
End Sub
Thanks a lot.