2012-12-14 57 views
-1

有人能幫助我如何檢查我的數據庫是否已經更新後,我做了一個編輯,這裏是我的代碼..我的代碼只是做一個編輯,然後在數據庫上更新它,什麼我不知道是如何檢查更新發生..檢查SQL更新

Dim dT As DataTable = MyDB.ExecCommand("SELECT `Field Name` FROM `tblfield` ORDER BY `Field Order`", "wellsfargo").Tables(0) 

      For i As Integer = 1 To flp.Controls.Count - 1 
       Application.DoEvents() 
       Dim xHead As uHead = DirectCast(flp.Controls(0), uHead) 
       Dim xCont As uControl = DirectCast(flp.Controls(i), uControl) 
       Dim sSQL As String = "" 

       Dim dZ As DataTable = MyDB.ExecCommand("SELECT * FROM `" + MyJob + "` WHERE `Record Number`='" + rNum + _ 
                 "' AND `Line Number`='" + xCont.lblLine.Text.Trim.Replace("'", "\'") + "'", "wellsfargo").Tables(0) 

       If dZ.Rows.Count <> 0 Then 
        sSQL = "UPDATE `" & MyJob & "` SET " 
        sSQL = sSQL + "`Orig Document Begin ID`='" + xHead.txtOrigBegDoc.Text.Trim + "'" 
        sSQL = sSQL + ",`Orig Document End ID`='" + xHead.txtOrigEndDoc.Text.Trim + "'" 
        sSQL = sSQL + ",`Beg Doc`='" + xHead.txtBegDoc.Text.Trim + "'" 
        sSQL = sSQL + ",`End Doc`='" + xHead.txtEndDoc.Text.Trim + "'" 
        sSQL = sSQL + ",`Loan Number`='" + xHead.txtLoan.Text.Trim + "'" 
        sSQL = sSQL + ",`Page Count`='" + xHead.txtPage.Text.Trim + "'" 
        sSQL = sSQL + ",`Path`='" + xHead.txtPath.Text.Trim + "'" 
        sSQL = sSQL + ",`File Number`='" + xHead.txtFileNumber.Text.Trim + "'" 
        sSQL = sSQL + ",`Settlement`='" + xHead.txtDate.Text.Trim + "'" 
        sSQL = sSQL + ",`Long and Foster`='" + xHead.txtLaF.Text.Trim + "'" 
        sSQL = sSQL + ",`Comment`='" + xHead.txtComm.Text.Trim + "'" 
        sSQL = sSQL + ",`Description`='" + xCont.cboDesc.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Amount`='" + xCont.txtAmount.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Payee`='" + xCont.txtPayee.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Borrower`='" + xCont.txtBorrower.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Seller`='" + xCont.txtSeller.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Prosperity Borrower`='" + xCont.txtPBorrower.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL + ",`Prosperity Seller`='" + xCont.txtPSeller.Text.Trim.Replace("'", "\'") + "'" 
        sSQL = sSQL & " WHERE `Record Number` = '" & rNum & _ 
            "' AND `Line Number`='" + xCont.lblLine.Text.Trim.Replace("'", "\'") + "'" 
        MyDB.ExecQuery(sSQL, "wellsfargo") 
       Else 
        Dim sColumn As String = "" 

        For z As Integer = 0 To dT.Rows.Count - 1 
         If z = 0 Then 
          sColumn = "`" & dT.Rows(z).Item(0).ToString & "`" 
         Else 
          sColumn = sColumn & ",`" & dT.Rows(z).Item(0).ToString & "`" 
         End If 
        Next 
        sSQL = "INSERT INTO `" + MyJob + "` (" + sColumn + ") VALUES (" + _ 
        "'" + rNum + "'," + _ 
        "'" + xHead.txtOrigBegDoc.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtOrigEndDoc.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtBegDoc.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtEndDoc.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtLoan.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtPage.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtPath.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtFileNumber.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtDate.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtLaF.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xHead.txtComm.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.lblLine.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.cboDesc.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtAmount.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtPayee.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtBorrower.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtSeller.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtPBorrower.Text.Trim.Replace("'", "\'") + "'," + _ 
        "'" + xCont.txtPSeller.Text.Trim.Replace("'", "\'") + "')" 
        MyDB.ExecQuery(sSQL, "wellsfargo") 
       End If 

      Next 
MsgBox("Record successfully modified!", MsgBoxStyle.Information, Me.Text) 
+0

使用'SELECT',Luke。 – zerkms

+0

你的意思是,就像在做一個'SELECT'之後,檢查可能的錯誤,你有什麼樣的檢查? – madth3

+0

我只想檢查我的更新代碼是否可以更新並更改數據庫 – kelvzy

回答

0

通常沒有太大的意義,以檢查 - 如果事情是會錯將引發異常。 你可以將它包裝到存儲過程中並檢查@@ rowcount變量。 或者真的只是讓新的選擇來讀取變化的數據。