Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save Changes to DataSet

Status
Not open for further replies.

dedo8816

Programmer
Oct 25, 2006
94
GB
Hi,

I have a table that contains Data in an MS Access DB. Im trying to set my program to delete all data in a single table using the below code:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim Rows As DataRow
For Each Rows In Label_LocationsDataSet.TransferLabels.Rows
Rows.Delete()
Next
Label_LocationsDataSet.TransferLabels.AcceptChanges()
End Sub

Why won't this save changes in the database? As soon as i click my "Refresh Data" button set to empty then refill the Dataset, everything re-appears again. By the way for those who haven't recognised my noviceness, yes i am a novice...

Once again, thanks in advance for any and all help

D
 
Ok, just an update before someone recommends this i tried the following:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Rows As DataRow
For Each Rows In Label_LocationsDataSet.TransferLabels.Rows
Rows.Delete()
Next

Try
Me.Validate()
Me.TransferLabelsBindingSource.EndEdit()
Me.TransferLabelsTableAdapter.Update(Me.Label_LocationsDataSet.TransferLabels)
MsgBox("Update successful")

Catch ex As Exception
MsgBox("Update failed")
End Try

End Sub

This just gives me a message saying "Update Failed" and when i click my refresh button, yet again all the info is back...
 
You probably have not configured your Insert, Update and Delete Commands for your DataAdapter.
 
Hi Riverguy,

If all im doing is deleting rows of information and not inserting anything new do i still have to configure these commands?

All i need to do with this particular dataset is erase all rows then force the changes to the database so that when i click refresh, the old information doesn't reappear.

I'll try configuring an insert command, if i do this can information be copied directly from excel into the datagrid and saved?? This could be very handy...

D
 
If all im doing is deleting rows of information and not inserting anything new do i still have to configure these commands?

At the very least, you need to either configure the Delete command or write your own deletion routine to loop through the DataSet, firing off a delete against your database for each deleted row.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top