ADO.NET Update Question

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)

End Sub
[/code]


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 :)


Comments

  • Yes. You can call RejectChanges and be done with it. RejectChanges will look at the RowStatus and Undo anything done since the last call to AcceptChanges. Be careful... it will undo ALL changes since last call to AcceptChanges not just the changes from this function. The DataAdapter.Update() will call AcceptChanges for you and if YOU call AcceptChanges(), you will have to have updated the database manually through some SQL/SProc.

    -Ray
  • : Yes. You can call RejectChanges and be done with it. RejectChanges will look at the RowStatus and Undo anything done since the last call to AcceptChanges. Be careful... it will undo ALL changes since last call to AcceptChanges not just the changes from this function. The DataAdapter.Update() will call AcceptChanges for you and if YOU call AcceptChanges(), you will have to have updated the database manually through some SQL/SProc.
    :
    : -Ray
    :


    Thanks. :)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories