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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO.Net Update Question 1

Status
Not open for further replies.

NipsMG

Programmer
Dec 27, 2000
215
US
I'm finally started to get ADO.NET, but I have a specific question.

I have two tables, BatchInfo and Data. BatchINFO has a BatchID field, and Data has a BatchID field too, as a there's a key relationship, requireing data to have a BatchID from BatchINFO, and not allowing BatchINFO data to be deleted if there's still data for that BatchID in the data table.

I'm Planning on doing updates like this:

I'll have a dataset, dsData that will have both tables.
Code:
Public Sub AddData(ByVal BatchId as Integer)

Dim tblBatchInfo as DataTable
Dim tblData as DataTable

tblBatchInfo = dsData.Tables("BatchInfo")
tblData = dsData.Tables("Data")

Dim rowCurrent as DataRow
rowCurrent = tblBatchInfo.NewRow()
rowCurrent("BatchID") = BatchID
'**** Fill IN BatchInfo Row *****

tblBatchInfo.Rows.Add(rowCurrent)

'***** Add some data *****
rowCurrent = tblData.NewRow
rowCurrent("BatchID") = BatchID
rowCurrent("Data") = "Data1"
tblData.Rows.Add(rowCurrent)

'***** Add some data *****
rowCurrent = tblData.NewRow
rowCurrent("BatchID") = BatchID
rowCurrent("Data") = "Data1"
tblData.Rows.Add(rowCurrent)

Now, note that I haven't done a daAdapter.Update command to send these changes back to the database.

Now here's my question:

If someone CANCELS this operation, and I don't want to send ANY of this data to the database now, can I just do a dsData.RejectChanges and be done w/ it?

Do I have to go through the table objects and delete each of the rows I just added? How do I completely kill all the changes I just made?

Thanks In Advance!

--NipsMG s-)
 
No you don't have to do anything with the table (Unless you like to write a lot of code).

MSDN says --

"When RejectChanges is called, any DataRow objects that are still in edit-mode cancel their edits. New rows are removed. Rows with the DataRowState set to Modified or Deleted return back to their original state."

If you want to get rid of the data completley (wipe out all of the rows) then call the clear method on the datasets.

dsData.Clear()

Hope this helps,

fellthor
 
Thanks. That's exactly what I was looking for. :)

Now I've got another question on AcceptChanges..

If I have a DataSet, make changes, call AcceptChanges, and NEVER do a DataAdapter.Update statement, NOTHING should be updated on the database end, right?

--NipsMG







 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top