I am trying to make a basic page in ASP.Net by inserting into a MSSQL database. When I run the page it does not insert anything and no error is produced :(
The connection string name is right as well as the table name and fields. This is my code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
    SqlConnection connection;

    protected void Page_Load(object sender, EventArgs e)
        connection = new SqlConnection(ConfigurationManager.ConnectionStrings["PaintingConnection"].ConnectionString);
    protected void btnSubmit_Click(object sender, EventArgs e)
        SqlCommand command = new SqlCommand("INSERT INTO PaintingTable(paintingAuthor, paintingPrice, paintingName) VALUES (@id_paintingAuthor, @id_paintingPrice, @id_paintingName)", connection);

        //insert author
        SqlParameter authorContent = new SqlParameter("@id_paintingAuthor", SqlDbType.NVarChar);
        authorContent.Value = txtAuthor.Text;

        //insert price
        SqlParameter priceContent = new SqlParameter("@id_paintingPrice", SqlDbType.NVarChar);
        priceContent.Value = txtPrice.Text;

        //insert painting name
        SqlParameter nameContent = new SqlParameter("@id_paintingName", SqlDbType.NVarChar);
        nameContent.Value = txtName.Text;

        /*insert image
        SqlParameter imageContent = new SqlParameter("@id_paintingImage", SqlDbType.VarChar);
        imageContent.Value = imageUpload.



Thank You :D

Try chaning command.BeginExecuteNonQuery() to command.ExecuteNonQuery()

Edited 4 Years Ago by AleMonteiro: miss spell

That seemed to work. Thank You!
What is the differnece between the two? Why did ExecuteNonQuery work but BeginExecuteNonQuery not work?

BeginExecuteNonQuery is for async operations and requires an EndExecuteNonQuery call for it to 'finish' the command. From the documentation:

The BeginExecuteNonQuery method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the EndExecuteNonQuery method to finish the operation. The BeginExecuteNonQuery method returns immediately (CommandTimeout has no effect on BeginExecuteNonQuery), but until the code executes the corresponding EndExecuteNonQuery method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same SqlCommand object. Calling the EndExecuteNonQuery before the command's execution is completed causes the SqlCommand object to block until the execution is finished.

This question has already been answered. Start a new discussion instead.