none
Update() a table using TableAdapter RRS feed

  • Question

  •  

    My web application uses the TableAdapters to access the database, recently I have encountered coding of a deleting a row of data that is FK'd to another table. When i try to use tableAdaptor.Update() method on the datatable, MSSQL is givine me an update timeout. THe following is my code:

     

    TableAdapterHelper is a VB port of Ryan Whitaker's "Transactions with TableAdapters, a lazy man's approach"

    http://weblogs.asp.net/ryanw/archive/2006/03/30/441529.aspx

     

    Code Snippet

    Try

    tx = EVRI_DataTier.TableAdapterHelper.BeginTransaction(Me.DynamicDataCellTA)

    For Each row As EVRI_DataTier.StudySummaryDS.DynamicTableRowRow In rowDT

    cellDT = Me.DynamicDataCellTA.GetDataByTableRowID(row.TableRowID) 'fails here

    If cellDT Is Nothing Then Return False

    If cellDT.Rows.Count = 0 Then Return False

    For colNumber As Integer = 1 To cellDT.Rows.Count

    cellDT.Rows(0).Delete()

    Me.DynamicDataCellTA.Update(cellDT.Rows(0))

    Next

    Next

    EVRI_DataTier.TableAdapterHelper.SetTransaction(Me.DynamicDataRowTA, tx)

    For Each row As EVRI_DataTier.StudySummaryDS.DynamicTableRowRow In rowDT

    row.Delete()

    Next

    Me.DynamicDataRowTA.Update(rowDT)

    EVRI_DataTier.TableAdapterHelper.SetTransaction(Me.DynamicDataTableTA, tx)

    tableDT.Rows(0).Delete()

    Me.DynamicDataTableTA.Update(tableDT)

    tx.Commit()

    Return True

    Catch ex As Exception

    tx.Rollback() : Throw ex

    Finally

    tx.Dispose()

    End Try

     

     

    Monday, May 5, 2008 8:01 PM