Saving Changes To DataSet in memory (without updating Database)

  • Thread starter Thread starter Aziz
  • Start date Start date
A

Aziz

Hello I have a system where a customer can order a metallic alloy
product that is made from a variety of base metals. Every time the
customer adds an alloy to their shopping list the system works out how
much base metals are needed are deducts the relevant amount from the
stocks table.

I have this code which finds the stock level for a specific metal and
then reduces it by the necessary amount.

If baseNeeded >
CInt(dsTurbobraze.BaseMetalStocks.Rows(k).Item("BaseInStock")) Then
Exit Sub

dsDataset.BaseMetalStocks.FindByBaseMetalCode("Zinc").BaseInStock = _
(dsDataset..BaseMetalStocks.FindByBaseMetalCode(Zinc).BaseInStock) -
CType(baseNeeded, Integer)

First time I call this it works fine. But second time I call it, it
uses the original value (5000) rather than the new amount.

If I do a .Update command it works fine, but I don't want to save
changes to the Database until the order has actually been confirmed.
How can I save the changes to the Dataset in memory without saving to
the actual Database?
 
I've found that it's getting the original value is because I have this
code:

Private Sub dgrProductSearch_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles
dgrProductSearch.CurrentCellChanged
dtCurrentBaseMetals.Clear()
sqlAlloyCode =
SeperateProductCode(dgrProductSearch.Item(dgrProductSearch.CurrentRowIndex,
0).ToString)(1)

daCurrentBaseMetals = New OleDb.OleDbDataAdapter("SELECT
BaseMetalStocks.BaseMetalCode, BaseMetalAlloy.BaseMetalPercent,
BaseMetalStocks.BaseCostPerGram, BaseMetalStocks.BaseInStock,
BaseMetalAlloy.BaseMetalCode AS Expr1 FROM (BaseMetalAlloy INNER JOIN
BaseMetalStocks ON BaseMetalAlloy.BaseMetalCode =
BaseMetalStocks.BaseMetalCode) WHERE (BaseMetalAlloy.AlloyCode = '" &
sqlAlloyCode & "')", conADOConnection)
daCurrentBaseMetals.Fill(dtCurrentBaseMetals)

which basically just returns all the related records in two tables for
a certain alloy code every time the alloy is selected in the DataGrid.

But it still doesn't solve my problem. How can I store a temporary copy
of the BaseMetalStocks table and modify while whilst having the
original untouched?
 
Never mind. Just worked out that a populated Dataset table can be
copied. *sigh* you always get the answers just after posting the
message. Typical.
 
Back
Top