Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application Exception Error message

Status
Not open for further replies.

JJ297

Programmer
Jun 27, 2007
30
0
0
US
Could someone tell me what I'm missing in my code, when I hit the submit button to add the question to my database I get...


FINALLY

Application Execption was unhandled by usercode, an error occurred while trying to insert the record.

I have a text box on the aspx page

<asp:TextBox ID="Txtquestion" runat="server" </asp:TextBox>

This is on the code behind page:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim question As String = Txtquestion.Text

Dim conn As New Data.SqlClient.SqlConnection("Server=SEB2A54;User ID=EDCSFAQUser; Password=fax " & _
"Initial Catalog=EDCSFAQS;Trusted_Connection=no")

'add string
Dim cmd As New Data.SqlClient.SqlCommand
With cmd

.Connection = conn 'the connection

.CommandType = Data.CommandType.StoredProcedure

.CommandText = "addques"
.Parameters.AddWithValue("@question", Txtquestion.Text)


End With
Dim success As Boolean = False

Try
conn.Open()

cmd.ExecuteNonQuery() 'executes the sql that I assign. don't need anything back from db

success = True

Catch ex As Data.SqlClient.SqlException

Throw New ApplicationException("An error occurred while trying to insert the record")
Finally
conn.Close()
End Try

If success Then
lbloutcome.Text = "Your entry was submitted into the
database."

Else
lbloutcome.Text = "Your entry failed."
End If
End Sub

Does anyone know what I did wrong? Could you please assist me?
Thanks
 
Debug your code. Put a stop on the Throw New ApplicationException Line. Then check the exception in ex.
 
Thanks that worked I found the problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top