Hello

I am using the following try | catch to locate an error:

Try

  Using conn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("students").ConnectionString)

 Dim Sql As String = "INSERT INTO university (username,[password], strEmail) VALUES (@username,@password, @strEmail)"

                Dim cmd As New OleDbCommand(Sql, conn)
                conn.Open()
                cmd.Parameters.AddWithValue("@username", username.Text)
                cmd.Parameters.AddWithValue("@password", password.Text)
                cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)

                cmd.ExecuteNonQuery()
                conn.Close()

            End Using

        Catch ex As Exception

            LabelMessage.Text = "There is a problem, " & ex.Message

        End Try

But Visual Studio 2013 does not like 'LabelMessage' so I doubt Try | Catch is working at all. 'LabelMessage' has a squiggly blue underline.

Is there anything else I can use?

The problem I have is that my form field data is inserted into my database locally, but not online on my Web site. My Web hosting service says all my server folder permissions are fine.

Thanks

What is the message associated with the squiggly line? I suspect your control has a slightly different name than the one you typed in the code.

I have actually commented out that line so my code looks like this:

Try

            Using conn As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("students").ConnectionString)

                Dim Sql As String = "INSERT INTO university (username,[password], strEmail) VALUES (@username,@password, @strEmail)"

                Dim cmd As New OleDbCommand(Sql, conn)
                conn.Open()
                cmd.Parameters.AddWithValue("@username", username.Text)
                cmd.Parameters.AddWithValue("@password", password.Text)
                cmd.Parameters.AddWithValue("@strEmail", strEmail.Text)

                cmd.ExecuteNonQuery()
                conn.Close()

            End Using

        Catch ex As Exception

            'LabelMessage.Text = "There is a problem, " & ex.Message

        End Try

and in the Output window that appears after I click on Build, I have:

Building directory '/'.

Validation Complete
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

I think that means 'no errors', doesn't it? Yet, there has to be an issue somewhere otherwise my form field data would be inserted into my online database.

I know it's not a server/folder permissions issue as my Web hosting service has checked and double-checked.

It's perplexing.

Replace

'LabelMessage.Text = "There is a problem, " & ex.Message

with

MsgBox(ex.Message)

Did you check to see if you had a typo in the control name?

There are no typos and when I run debug I don't get any errors, either.

I have inserted that, Reverend Jim:

 Catch ex As Exception

            MsgBox(ex.Message)

            'LabelMessage.Text = "There is a problem, " & ex.Message

        End Try

I don't get separate msg box popping up, only the Output window as in the link below:

Click Here

When you run the code either the TRY portion or the CATCH portion is going to execute. If you didn't get the MsgBox popup then there was no error. If that's the case then your query executed and you should check the database to see if the record was added. You might want to single step through the code to check the actual value of "sql" and the values of the text fields that are going into the query. Just out of curiosity, when you are in the editor and typing in the CATCH portion, when you enter

LabelMessage.

do you get the IntelliSense popup associated with the control? When you start typing the control name do you get IntelliSense suggesting control names for auto complete? Is one of those suggestions the actual control you want?

Hello Reverend

The form data is still not being inserted into the database.

Yes. I do get a list of suggestions after typing Label - please see screenshot.

Click Here

As you can see, there is only Label and LabelControlBuilder.

In any case, I have seen examples of try | catch where the 'Label' part has been omitted completely.

I am not sure what's wrong. If it makes any difference, myForm, which is my compilation 'target' folder, is a virtual directory set up by my Web hosting service, and is a sub-directory of 'root'.

Thanks again for your time.

Bluenose

Where is your code running? On your computer? Are you trying to update a database on your computer and on the web server?

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.