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

Changes to row and AcceptChanges...

Status
Not open for further replies.

NatHunter

Technical User
Aug 17, 2001
51
0
0
GB
I have a question regarding changes and AcceptChanges in ADO.NET.

The following code snippet does a select on a table - if the record is present the record is updated - if it is not present a new one is added. The code does work, but I'd like to tidy it up so that I don't have to, in effect, repeat lines. I've tried rowOrd = rowLupOrders(0), but then run into update issues. Any suggestions?

Also, can anyone clarify the mysterious 'AcceptChanges' command. It sometimes works for a row that exists already, but doesn't seem to work when adding a new row. Strangely there doesn't seem to be much documentation saying where it should actually be used.

Thanks

Paul

dim rowLUpOrder as datarow()

rowLUpOrder = ds.Tables("Orders").Select("[Date] =#" & DatestrSys & "#" & " and [Location] = '" & sLocation & "' AND [OrderTime] = '" & OrderTime & "'")

If rowlupOrders.Length > 0 Then
rowlupOrders(0).BeginEdit()
rowlupOrders(0)("Date") = dDate
rowlupOrders(0)("Location") = sLocation
rowlupOrders(0)("OrderTime") = sOrderTime
rowlupOrders(0)("OrderName") = Trim(sOrderName)
rowlupOrders(0).EndEdit()
rowlupOrders(0).AcceptChanges()
Else
'add a new record...
rowOrd = ds.Tables("Orders").NewRow
ds.Tables("Orders").Rows.Add(rowOrd)

rowOrd.BeginEdit()
rowOrd("Date") = dDate
rowOrd("Location") = sLocation
rowOrd("OrderTime") = sOrderTime
rowOrd("OrderName") = Trim(sOrderName)
rowOrd.EndEdit()
'rowOrd.AcceptChanges()
End If

Try
oOrderCon.da.Update(ds, "Orders")
'Catch ex As DBConcurrencyException
Catch ex As Exception
Call MsgBox(ex.Message)
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top