I'm currently started in asp.net C# on school, and now they want me to insert data into SQL Server. Now I came so far with this code, but when I try to add something into the database, I get the error:
SqlException was unhandled by user code
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Column name or number of supplied values does not match table definition.
Can someone explain me what I am doing wrong here?
Thanks in advance.
Fred.
public partial class AddMovie : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["VideoStoreConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("INSERT INTO dbo.Movie values('" + txtmovie.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
Label1.Visible = true;
Label1.Text = "Your Movie is Stored Successfully!";
txtmovie.Text = "";
}
}