Search code examples
sqlinsertexecutequery

Insert SQL Query not executed


I am doing the programming on my computer and it works fine-the program, the database itself, inserting to the database is also working fine. But when I publish it and install the program on another computer. It crashes and does not execute the INSERT command.

Here is my code.

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 transport=@transport AND blnum=@blnum"

    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

Please tell me what I am doing wrong? When I run and install the program on my PC, it works perfectly fine. But when I run/install it on another PC, it crashes after the cmdBlank is clicked.


Solution

  • AS400 iSeries DB2 needs to be updated to version 6.xx.0800 and did the tweak!

    Installer can be found here http://www-03.ibm.com/systems/power/software/i/access/windows_sp.html

    Problem solved!