I have a problem with asp.net insertion data in SQL data base. I am using SQL Express with ASP.NET 4.0. I had written the code correctly and it was working fine as well, but now it does not insert the data in the database. It started behaving abnormally when I made the some changes in ASP.NET form. When I run the application it shows me that it has inserted the data entered but when I look into the database, there is nothing there.
The code is given below:
I mports System.Data Imports System.Data.SqlClient Imports System.Web.Configuration Imports System.Linq Imports System.Text Imports System.Web.UI.WebControls.RadioButtonList Partial Class Registration Inherits System.Web.UI.Page Protected Sub RegisterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles RegisterButton.Click If FirstNameText.Text = "" Or LastNameText.Text = "" Or EmailAddressText.Text = "" GenderList.SelectedIndex = False Then EntryMissingWarningLabel.Text = "Please fill in all the fields above." End If Dim connectionstring As String = WebConfigurationManager.ConnectionStrings("Register").ConnectionString Dim insertcommand As String insertcommand = "insert into Medpoint_Register values (@FirstName, @LastName, @Email, @Gender)" Dim reg_connection As New SqlConnection(connectionstring) Dim reg_command As New SqlCommand(insertcommand, reg_connection) reg_command.Parameters.AddWithValue("@FirstName", FirstNameText.Text) reg_command.Parameters.AddWithValue("@LastName", LastNameText.Text) reg_command.Parameters.AddWithValue("@Email", EmailAddressText.Text) reg_command.Parameters.AddWithValue("@Gender", GenderList.SelectedIndex) Dim added As Integer = 0 Try reg_connection.Open() added = reg_command.ExecuteNonQuery() AddedLabel.Text = added.ToString() & "Record Added" Catch err As SqlException Error1Label.Text = "Problem in inserting the data. Please try again" Finally reg_connection.Close() End Try ' reg_connection.Close() Response.Redirect("RegistrationRedirect.aspx") End Sub End Class
Please help me with this... I have checked the code so many timesm but it seems ok to me.
Thank you in anticipation.
Bilal A. Khan