Hi! 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.

Add parameters after assigning the CommendText Property (Line No 45).

This is the parameter already.

 With cmdAdd
    .Parameters.AddWithValue("@page", Val(frmPart1.txtPage.Text)) 
    .CommandText = sqlAdd
    .Connection = conn
    .ExecuteNonQuery()
End With

ohhh! you assign the parameters before assigning the CommandText property.
First assign the CommandText Property then Parameters.

Again, the code above works on my programming PC very well. But on the other PC, it does not. What I would like to know is that, do I need to install something to other PC?

P.S. I tried your suggestion @Santanu Das but it does not work also.

Ok here's couple of things you can try:

  • Find out what the error is by adding this code:

    Try
    'your code here
    Catch ex As Exception
    MessageBox.Show(ex.Message & " - " & ex.Source)
    End Try

  • Go to your project properties >> publish >> then check the "application files" and the "prerequisites" button, so that you can add everything your program needs to operate properly, everything you add will be added to the installer.

  • Change your targeted platform to X86 bit so that your program will work on both systems (32-bit and 64-bit).
    go to Build >> configuration manager >> platform >> new >> X86 >> ok.

Good Luck

hi! i've already tried the try & catch method but it does not work. The Message Box does not appear exactly.

targeted platform is also set to X86.

But when I publish it and install the program on another computer.

What kind of database are you using, and did you deploy that with the program?

What operating system? If Vista or newer (win 7, win 8), check that the user account control settings are the same on both computers.

Also, you might want see if a simple program (such as one that only opens a message box) runs on the other computer.

MessageBox.Show("Hello World")

Additionally, you can use the attached module "Module1.vb" to retrieve some additional computer information and compare the values on both computers.

To use it, just call "getInfo":

getInfo()

Hi Guys!

I am using AS/400 iSeries DB2 as my database.

Here's the scenario, on my program I have a View Data form wherein it retrieves data from the database and displays it in a datagridview. The user selects which item he wants to print, afterwhich a form with a Reportviewer on it displays. Again, this works well on my PC and on the test PC.

What does not work is the execution of the INSERT COMMAND. I tried also to put a Message Box to test if it works. Because before the INSERT COMMAND, I have another SELECT COMMAND wherein it verifies duplicate entries on the database using COUNT(*) and again this also works well. I get the value of 0 if no matches found. I tried to display the Message Box before the INSERT COMMAND, it works! But when I place it after the INSERT COMMAND, it does not work at all. The Message Box is not displayed as well as the INSERT COMMAND is not executed.

I have the Reportviewer redistributable package installed on the test PC. I have also installed MS Visual Studio 2010 to run the program there. According to the Immediate Window, The xxx.exe has exited at code 0. Something like that. I've researched and some says that I need to reinstall the .NET Framework, currently I am trying to that now.

As I said also, this whole program works very well on my computer. But when I try to install the setup.exe or run the program itself on another computer, it does not work at all. I am wondering if I have overlooked some components which I need to install first on the test PC? Kindly help me please, thanks! :)

What version of .NET are you using? What version of ReportViewer did you install?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.