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
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