I am trying to make a simple website that gets your registration details and stores it in a sql database
But I am getting a error saying
System.Data.SqlClient.SqlException: 'Incorrect syntax near '-'.'
Here is my code:
using System;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Collections.Generic;
namespace ARTIst_Sketch_Work
{
public partial class Registeration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Register.mdf;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into [Table] (Username,E-mail,Age,Gender,PhoneNo,Address,Password,ConfirmPassword) values('" + TextBox.Text + "', '" + TextBoxEmail.Text + "', '" + TextBoxAge.Text + "', '" + DD_Gender.Text + "', '" + TextBoxPhone.Text + "', '" + TextBoxAddress.Text + "', '" + TextBoxPa.Text + "', '" + TextBoxCpass.Text + "');";
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
The exception pops at :
cmd.ExecuteNonQuery();
Any help will be appreciated