0

On my markup, I am using image button to update a record on the db.

This has always worked till now.

Now, users get the following error:

Conditional Compilation is turned off

It says line 1 charachter 33.

I have no idea what this means.

Markup code:

<asp:ImageButton ID="saveButton" title="Save" runat="server" OnClick="saveButton_Click" ImageUrl="images/BTN-save.gif" 
                                             onmouseout="this.src='images/BTN-save.gif'" 
                                             onmouseover="this.src='images/BTN-save.gif'"

Sub:

Protected Sub saveButton_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
    Dim myConnectionString As [String] = ConfigurationManager.ConnectionStrings("DBConnectionString").ConnectionString
    Dim myConnection As New SqlConnection(myConnectionString)
    Try
        myConnection.Open()
        Dim cmd As New SqlCommand("UPDATE tblLogin SET fullname=@fullname,Address=@address,Email=@email, Precinct=@precinct, positionid = @position where " + "username=@username and email=@email", myConnection)
        cmd.Parameters.AddWithValue("@fullname", NameTB.Text)
        cmd.Parameters.AddWithValue("@address", AddressTB.Text)
        cmd.Parameters.AddWithValue("@email", EmailTB.Text)
        cmd.Parameters.AddWithValue("@precinct", precinctList.SelectedValue)
        cmd.Parameters.AddWithValue("@position", PositionList.SelectedIndex)
        cmd.Parameters.AddWithValue("@username", Session("username"))
        cmd.Parameters.AddWithValue("@email", Session("UserId"))
        Dim rows As Integer = cmd.ExecuteNonQuery()
        If rows = 1 Then
            Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('Information Saved successfully')</SCRIPT>")
            Response.Redirect("~/myAccount.aspx")
        End If
    Catch ex As SqlException
        Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + ex.Message + "')</SCRIPT>")
    Finally
        myConnection.Close()
    End Try
End Sub

I suspect it has to do with the image but I am not sure.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Chidi Okeh
  • 1,537
  • 8
  • 28
  • 50
  • Sounds like there's a conflicting parameter in the page directive of the source page. Look at those settings and if nothing is obvious, edit your post to include them. – Erik Noren Oct 24 '13 at 18:57
  • @ErikNoren, excellent catch. I had '@email' twice as you can see above. Unfortunately, Try...Catch didn't catch that one. I had to comment out Try...Catch to catch it. Working well now. I will be glad to give you credit sir for your assistance. – Chidi Okeh Oct 24 '13 at 19:13
  • I added as an answer. But it sounds like it wasn't the actual answer. Darn misleading error messages! – Erik Noren Oct 24 '13 at 20:13

1 Answers1

0

Added comment as an answer: Sounds like there's a conflicting parameter in the page directive of the source page. Look at those settings and if nothing is obvious, edit your post to include them.

Edit: Sounds like the duplicate command parameter was the issue. Misleading errors are the bane of my existence!

Erik Noren
  • 4,279
  • 1
  • 23
  • 29