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;
command.Parameters.Add(authorContent);
//insert price
SqlParameter priceContent = new SqlParameter("@id_paintingPrice", SqlDbType.NVarChar);
priceContent.Value = txtPrice.Text;
command.Parameters.Add(priceContent);
//insert painting name
SqlParameter nameContent = new SqlParameter("@id_paintingName", SqlDbType.NVarChar);
nameContent.Value = txtName.Text;
command.Parameters.Add(nameContent);
/*insert image
SqlParameter imageContent = new SqlParameter("@id_paintingImage", SqlDbType.VarChar);
imageContent.Value = imageUpload.
command.Parameters.Add(imageContent);*/
connection.Open();
command.BeginExecuteNonQuery();
connection.Close();
Response.Redirect("Results.aspx");
}
}
Thank You :D