Cannot update dataset into access database

kekewong

Member
Joined
Mar 9, 2009
Messages
7
Programming Experience
Beginner
Ok, my current situation is i got a datagridview , some field i bind it with my Food_Ordering dataset , some do not , and in my datagridview, i add 1 more button column and gives a delete function to do . That means , my mission is , user click the button of particular row, it should delete from the dataset Food_Ordering table and update into database .But it seems like the database wont update , but my datagridview item has been delete.

Ok, another finding that i found is . Assume that i have only 1 row of record in Food_Ordering. I press delete , the particular datagridview row has been delete, but i close the form and show it back , the record still remains . So , i try to press delete again , this time it says " there are no item in row (0). So, i was wondering, the dataset table has been successfully delete the row, but it just haven update into the database . I tried to open the database and see whether the record is still there, and the answer is yes . The record never delete in database. So ... Why is this happening? Below is some of my codes .
VB.NET:
 Private Sub dgvFoodOrdering_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvFoodOrdering.CellContentClick
        
        If (e.ColumnIndex = dgvFoodOrdering.Columns("Delete").Index) Then
            If (MessageBox.Show("Do you really want to delete this record?", "Delete Comfirmation", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes) Then

         
                ds.Tables("Food_Ordering").Rows.Remove(ds.Tables("Food_Ordering").Rows(e.RowIndex))
                dgvFoodOrdering.Rows.RemoveAt(e.RowIndex)
                daFoodOrder.Update(ds)
            End If
        End If
    End Sub
 
hmm , kind of weird , i now can delete the record by using .delete() method . Just refering to this link How to update a database from a DataSet object by using Visual Basic .NET

To delete a row completely, use the Delete method of the DataRow object. Note that the Rows collection contains two methods, Remove and RemoveAt, which seem to delete the row but instead just remove the row from the collection. Only the Delete method sends your deletion back to the source database. Paste the following code after the SEND CHANGES TO SQL SERVER code:

i think only delete method can do this .:cool:
 
To delete a row you need to retrieve it from the database into a DataRow in a DataTable, call its Delete method to flag it as deleted, then save the DataTable's changes back to the database, at which point the record that corresponds to the flagged row is deleted. If you call Remove or RemoveAt the row gets removed from the collection, as though it was never there. If you do that there's no way to tell the database to delete the original record.
 

Latest posts

Back
Top