Header Ads

  • Breaking News

    Db Transaction

    ''' การทำ  DbTransaction 
    กรณีที่ข้อมูล Insert ไม่ครบ จะ Rollback กลับมา น่ะจ๊ะ Insert บ่ ได้ เด้อแบบนี้ ...... 

    Dim str As String = "Provider=msdaora;Data Source=XE;User Id=DAIWA;Password=system;"
            Dim dbCon As New OleDbConnection(str)
            dbCon.Open()

            Dim CTNSPLNO As String = "555555555555555"
            Dim REFTYPE As String = "01"
            Dim CUSPARTNO As String = "11"
            Dim DATPARTNO As String = "222"
            Dim MOLDNO As String = "222"
            Dim CTNRUNNO As String = "6"
            Dim LOTNO As String = "222"
            Dim ORDERNO As String = " "
            Dim PONO As String = " "
            Dim INVOICENO As String = "222"
            Dim TXQTY As String = "66"
            Dim OPERID As String = "222"


            Dim Trans As OleDbTransaction
            Trans = dbCon.BeginTransaction(IsolationLevel.ReadCommitted)

            With scmd
                .Connection = dbCon
                .Transaction = Trans


    End With
    Try
    Dim ssQl As String = "INSERT INTO tbd_invrecords " & _
                    "(CTNSPLNO,REFTYPE,REFDTE,DATPARTNO,CUSPARTNO,MOLDNO,CTNRUNNO,TXQTY,OPERID,LOTNO,UPDDTE,SYSDTE)" & _
                    " VALUES ('" & Trim(CTNSPLNO) & "', " & _
                    " '" & Trim(REFTYPE) & "', " & _
                    "   sysdate , " & _
                    " '" & Trim(DATPARTNO) & "',  " & _
                    " '" & Trim(CUSPARTNO) & "',  " & _
                    " '" & Trim(MOLDNO) & "', " & _
                    " '" & Trim(CTNRUNNO) & "', " & _
                    " '" & Trim(TXQTY) & "'," & _
                    " '" & Trim(OPERID) & "', " & _
                    " '" & Trim(LOTNO) & "', " & _
                    "   sysdate, " & _
                    "   sysdate)"

                With scmd
                    .CommandText = ssQl
                    .CommandType = CommandType.Text
                    .ExecuteNonQuery()

                End With
                Trans.Commit()
            Catch ex As Exception
                Trans.Rollback()
            End Try

        End Sub


    ไม่มีความคิดเห็น

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728