DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   detecting delete on row in datagridview and updating dataset (http://www.daniweb.com/forums/thread158804.html)

ninjaimp Nov 21st, 2008 12:26 pm
detecting delete on row in datagridview and updating dataset
 
i have a datagrid which show values in a dataset.

I can add new values fine with the below code, but when i delete one of the rows (highlighting a row and using the delete key) i get the error:

'Update requires a valid DeleteCommand when passed DataRow collection with deleted rows.'

this is flaggin on the bolded line below

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim drNew As System.Data.DataRow

        drNew = Me.ISurfDataSet.Urls.NewRow
        drNew.Item("URLLink") = urlTextBox.Text
        Me.ISurfDataSet.Urls.Rows.Add(drNew)

        Changes = True 'set the flag to show that changes have been made

    End Sub

    Sub AddData() ' add the new urls to the database



        Me.Validate()
        Me.UrlsBindingSource.EndEdit()
        Me.UrlsTableAdapter.Update(Me.ISurfDataSet.Urls)

        MsgBox("All new data added successfully!")

        Changes = False ' all canges have been saved so the form can close

        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call AddData() ' call the function to add the new urls to the database

    End Sub

    Private Sub UrlsDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles UrlsDataGridView.UserDeletedRow
        Me.Validate()
        Me.UrlsBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ISurfDataSet)
    End Sub


any help is appreciated


All times are GMT -4. The time now is 10:12 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC