Duplicating Row in a Dataset

dec21st

Active member
Joined
May 14, 2005
Messages
43
Programming Experience
3-5
i'm having problem trying to copy a row from a dataset table and inserting it back on the same table. the reason why i'm doing this is to paste the new row and edit 2 columns.

i tried using dataset.clone .copy .merge and to no avail, i've given up. using these method disallow me to copy because i have a column with identity (auto incremental). it's a read only column that automatically generate the primary key. i encounter integrity constraint when i try to use those method

i will include a sample of my temporary solution
hope that you all can help in how to minimise my code length with a better solution

VB.NET:
Public Function ChkToCanc(ByRef cFinMsgOutMT300Data As FinMsgOutMT300Data, ByVal sDealID As String) As Boolean

        Dim drwFinMsgOutMT300Row As FinMsgOutMT300Data.FinMsgOut_MT300Row()
        Dim drwCANCFinMsgOutMT300Row As FinMsgOutMT300Data.FinMsgOut_MT300Row

        drwFinMsgOutMT300Row = CType(cFinMsgOutMT300Data.FinMsgOut_MT300.Select("DealID = '" & sDealID & "' AND MsgStatus = '2' AND RStatus = 'A'"), FinMsgOutMT300Data.FinMsgOut_MT300Row())
        drwCANCFinMsgOutMT300Row = cFinMsgOutMT300Data.FinMsgOut_MT300.NewFinMsgOut_MT300Row

        If drwFinMsgOutMT300Row.Length > 0 Then
            For iRow As Integer = 0 To drwFinMsgOutMT300Row.Length - 1
                Dim uidMessageID As Guid

                For iRow2 As Integer = 0 To cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).ItemArray.GetUpperBound(0)
                    'If Not cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).Item(iRow2) Is cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).Item("SeqNo") Then
                    If Not iRow2 = 3 Then   'If item("SeqNo")
                        drwCANCFinMsgOutMT300Row.Item(iRow2) = drwFinMsgOutMT300Row(iRow).Item(iRow2)
                    End If
                Next

                With drwCANCFinMsgOutMT300Row
                    .Item("MsgStatus") = sMsgStatusCanc
                    '.MatchStatus = sMatchStatus
                    .Item("uidMessageID") = uidMessageID.NewGuid
                    .Item("RelatedReference_A_21") = .Item("DealId")
                    .Item("TypeOfOperation_A_22A") = CANC
                    .Item("EntDt") = decUpdDt
                    .Item("EntTime") = decUpdTime
                    .Item("EntBy") = _sUpdBy
                    .Item("EntWS") = _sUpdWs
                End With
                drwFinMsgOutMT300Row(iRow).RStatus = "D"
                cFinMsgOutMT300Data.FinMsgOut_MT300.Rows.Add(drwCANCFinMsgOutMT300Row)
            Next
        End If
    End Function
basically the drwFinMsgOutMT300Row (datarow) is my existing row which i wanna extract one row out to drwCANCFinMsgOutMT300Row (datarow) and then inserting it back to my cFinMsgOutMT300Data (dataset)

-------------------------------------------------------

actually i have another problem as well. if i were to use the above solution, i discover a problem when i want to copy the rows

VB.NET:
For iRow2 As Integer = 0 To cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).ItemArray.GetUpperBound(0)
                    'If Not cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).Item(iRow2) Is cFinMsgOutMT300Data.FinMsgOut_MT300.Rows(0).Item("SeqNo") Then
                    If Not iRow2 = 3 Then   'If item("SeqNo")
                        drwCANCFinMsgOutMT300Row.Item(iRow2) = drwFinMsgOutMT300Row(iRow).Item(iRow2)
                    End If
                Next
as you can see, i've comment out one line. the reason why i do that is because it doesn't skip when iRow = 3 (that's when the object is .Item("SeqNo")). anyway i can use that instead of hardcoding it to 3.
maybe i need to convert the object to another type so that it can match. i want to skip that particular column because its the primary key (it will disallow me to add row if i copy that as well)
 
Back
Top