after I delete in row datagridview then I update to database with "BTNUPDATE" but there is an error is there something wrong with my code.
if binding directly to datagridview without binding source then there is no error on "BTNUPDATE" but error on "BTNDELETE"
Thanks
Dear sir,
after I delete in row datagridview then I update to database with "BTNUPDATE" but there is an error is there something wrong with my code.
Thanks
Dim pservice As New personService
Private _source As New BindingSource()
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
_source.DataSource = pservice.GetPersondetail()
DataGridView1.DataSource = _source
End Sub
Private Sub BTNDELETE_Click(sender As Object, e As EventArgs) Handles BTNDELETE.Click
For Each dvr As DataGridViewRow In DataGridView1.SelectedRows
If dvr IsNot Nothing Then
DataGridView1.Rows.Remove(dvr)
DataGridView1.Refresh()
End If
Next dvr
End Sub
Private Sub BTNUPDATE_Click(sender As Object, e As EventArgs) Handles BTNUPDATE.Click
Try
If DataGridView1.RowCount = 0 Then
Throw New Exception("no data")
End If
For Each item As DataGridViewRow In DataGridView1.Rows
Dim detail = DirectCast(item.DataBoundItem, persondetail)
Dim GetStocks = New persondetail With {
.Nameperson = detail.Nameperson,
.Age = detail.Age,
.Job = detail.Job,
.ID = detail.ID,
.Invono = detail.Invono}
pservice.UpdatePersondetail(detail)
Next item
MessageBox.Show("successfully")
Catch ex As Exception
MessageBox.Show(ex.Message, "myapp", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
End Sub
I want to be able to update with the "BTNUPDATE" event please recommend
as recommended by @jmcilhinney