我正在做我的計算機上的編程,它工作正常 - 程序,數據庫本身,插入到數據庫也工作正常。但是,當我發佈它並在另一臺計算機上安裝該程序時。它崩潰並且不執行INSERT命令。插入SQL查詢未執行
這是我的代碼。
Private Sub cmdBlank_Click(sender As System.Object, e As System.EventArgs) Handles cmdBlank.Click
strTariff1 = txtPart1.Text & " " & txtPName1.Text & " " & txtQty1.Text & " " & txtU1.Text
strTariff2 = txtPart2.Text & " " & txtPName2.Text & " " & txtQty2.Text & " " & txtU2.Text
strTariff3 = txtPart3.Text & " " & txtPName3.Text & " " & txtQty3.Text & " " & txtU3.Text
strTariff4 = txtPart4.Text & " " & txtPName4.Text & " " & txtQty4.Text & " " & txtU4.Text
'strTariff5 = txtPart5.Text & " " & txtPName5.Text & " " & txtQty5.Text & " " & txtU5.Text
Call saveToDb()
frmreportax.Show()
End Sub
Private Function saveToDb()
conn.Close()
Dim cmdAdd, cmdCount, cmdAdd2 As New iDB2Command
Dim sqlAdd, sqlCount, sqlAdd2 As String
Dim curr1, curr2, curr3, curr4 As String
Dim count As Integer
conn.ConnectionString = str
conn.Open()
'Check for duplicate entry
sqlCount = "SELECT COUNT(*) AS count FROM cewe WHERE [email protected] AND [email protected]"
With cmdCount
.CommandText = sqlCount
.Connection = conn
.Parameters.AddWithValue("@transport", frmPart1.txtTransport.Text)
.Parameters.AddWithValue("@blnum", frmPart1.txtNo.Text)
End With
count = Convert.ToInt32(cmdCount.ExecuteScalar())
If count <> 0 Then
MsgBox("Duplicate Entry: " & frmPart1.txtTransport.Text, vbOKOnly + vbExclamation)
Else
sqlAdd = "INSERT INTO cewe (page) " & _
"VALUES (@page) "
With cmdAdd
.Parameters.AddWithValue("@page", Val(frmPart1.txtPage.Text))
.CommandText = sqlAdd
.Connection = conn
.ExecuteNonQuery()
End With
end if
cmdAdd.Dispose()
cmdAdd2.Dispose()
conn.Close()
end function
請告訴我我做錯了什麼?當我運行並在我的電腦上安裝該程序時,它工作得很好。但是當我在另一臺PC上運行/安裝它時,它會在單擊cmdBlank後崩潰。
這可能是數據庫連接的問題(安裝或配置與應用程序正確運行)。通過應用程序記錄異常\錯誤,以確定問題到底是什麼。 – souser 2014-09-30 04:28:38
我如何記錄異常\錯誤? – shesxue28 2014-09-30 04:38:32
查看企業庫的日誌記錄模塊。或者,您可以簡單地將插入引發的異常詳細信息記錄在簡單的文本文件中。 – souser 2014-10-02 01:12:32