protected void btnAdd_Click(object sender, EventArgs e)
    {
        string connectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=JobApplication; Trusted_Connection=True; Integrated Security=True";

        SqlConnection mySqlconn = new SqlConnection(connectionString);

        mySqlconn.Open();

        string query = "INSERT into JobVacancy(JobName, BriefDesc, FullDesc, ClosingDate) VALUES (@jobtitle, @briefdesc, @fulldesc, @closedate)";

        SqlCommand mySqlcmd = new SqlCommand(query, mySqlconn);
        mySqlcmd.Parameters.AddWithValue("@jobtitle",jobtitle.Text);
        mySqlcmd.Parameters.AddWithValue("@briefdesc", briefdesc.Text);
        mySqlcmd.Parameters.AddWithValue("@fulldesc", fulldesc.Text);
        mySqlcmd.Parameters.AddWithValue("@closedate", closingdate.Text);

        int res = mySqlcmd.ExecuteNonQuery();
    }

I used the above code to insert value from the textboxes into the database.

On the aspx page, the code for the button is:

<asp:Button ID="btnAdd" runat="server" Text="Add Job" onclick="btnAdd_Click" PostBackUrl="../Prototype/AddConfirm.aspx"/>

When I clicked the button, the pages goes to AddConfirm.aspx but the the insertion doesn't work.

If I delete the PostBackUrl, the insertion works but the page didn't go anywhere.

Anybody can help?

after insertion do this

Response.Redirect("../Prototype/AddConfirm.aspx");

normally postback will occur to your same page, but postbackurl changes to the other page, thats why your insert doesn't occur

protected void btnAdd_Click(object sender, EventArgs e)
    {
        string connectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=JobApplication; Trusted_Connection=True; Integrated Security=True";

        SqlConnection mySqlconn = new SqlConnection(connectionString);

        mySqlconn.Open();

        string query = "INSERT into JobVacancy(JobName, BriefDesc, FullDesc, ClosingDate) VALUES (@jobtitle, @briefdesc, @fulldesc, @closedate)";

        SqlCommand mySqlcmd = new SqlCommand(query, mySqlconn);
        mySqlcmd.Parameters.AddWithValue("@jobtitle",jobtitle.Text);
        mySqlcmd.Parameters.AddWithValue("@briefdesc", briefdesc.Text);
        mySqlcmd.Parameters.AddWithValue("@fulldesc", fulldesc.Text);
        mySqlcmd.Parameters.AddWithValue("@closedate", closingdate.Text);

        int res = mySqlcmd.ExecuteNonQuery();


//after u inset 
Response.Redirect("../Prototy/AddConfirm.aspx");
    }
This question has already been answered. Start a new discussion instead.