Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i need to update orders table and its orders details when order is edited, here is what i have. But the issue here is that although am using a transaction, the order details items are not deleting from the database, instead the new values are being added to the old.

is there something am doing wrong?
VB
Dim cmd As New SQLiteCommand(sqlInvInsert, conn)
    'conn.SetPassword(DBPassword)
    conn.Open()
    Dim myTrans As SQLiteTransaction = conn.BeginTransaction()

    Try
        If value.id > 0 Then
            cmd = New SQLiteCommand(sqlInvUpdate, conn)
            cmd.Parameters.AddWithValue("@id", value.id)
        End If
        cmd.Parameters.AddWithValue("@customer", value.customer)
        cmd.Parameters.AddWithValue("@vessel", value.vessel)
        cmd.Parameters.AddWithValue("@size", value.size)
        cmd.Parameters.AddWithValue("@blno", value.blno)
        cmd.Parameters.AddWithValue("@commodity", value.commodity)
        cmd.Parameters.AddWithValue("@pol", value.pol)
        cmd.Parameters.AddWithValue("@pod", value.pod)

        Dim InvID As Integer

        If value.id > 0 Then
            InvID = value.id
            cmd = New SQLiteCommand("Delete From Items Where order_id=@id", conn)
            cmd.Parameters.AddWithValue("@id", value.id)
            cmd.ExecuteNonQuery()
        Else
            InvID = Convert.ToInt32(cmd.ExecuteNonQuery())
        End If

        cmd = New SQLiteCommand(My.Resources.itm_insert, conn)
        For Each itm As InvoiceItem In value.items
            cmd.Parameters.AddWithValue("@item", itm.Item)
            cmd.Parameters.AddWithValue("@desc", itm.Desc)
            cmd.Parameters.AddWithValue("@amount", itm.Amount)
            cmd.Parameters.AddWithValue("@order_id", InvID)
            cmd.ExecuteNonQuery()
        Next
        myTrans.Commit()

    Catch ex As Exception
        myTrans.Rollback()
        Throw
    Finally
        cmd.Dispose()
        conn.Dispose()
    End Try
Posted
Comments
ZurdoDev 30-May-13 7:51am    
You need to step through your code and see what is happening. It should be pretty easy to narrow down.
Cool Smith 30-May-13 8:14am    
i already did, and how do i see if the records are actually being deleted?

User cascade-delete option available at database level or every time you execute update records for order table, you need to delete order-details for the order_Id and insert all records.
 
Share this answer
 
User cascade-delete option available at database level or every time you execute update records for order table, you need to delete order-details for the order_Id and insert all records. By this logic, you need not to worry changes done by the end user in order-details (e.g whether to update or insert or delete)
 
Share this answer
 
i actually did a throughout debug and found that i was adding to the items without first deleting the previous from the user interface
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900