public partial class SignUp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btSignup_Click(object sender, EventArgs e)
{
if (tbUname.Text != "" & tbPass.Text != "" && tbName.Text != "" && tbEmail.Text != "" && tbCPass.Text != "")
{
if (tbPass.Text == tbCPass.Text)
{
String CS = ConfigurationManager.ConnectionStrings["Database_AvaliacaoConnectionString1"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("insert into Users Values('" + tbUname.Text + "','" + tbPass.Text + "','" + tbEmail.Text + "','" + tbName.Text + "','')", con);
con.Open();
cmd.ExecuteNonQuery();
lblMsg.Text = "Registration Successfull";
lblMsg.ForeColor = Color.Green;
// Response.Redirect("~/Signin.aspx");
}
}
else
{
lblMsg.ForeColor = Color.Red;
lblMsg.Text = "Passwords do not match";
}
}
else
{
lblMsg.ForeColor = Color.Red;
lblMsg.Text = "All Fields Are Mandatory";
}
}
}
In the Users table I got the following values
[Uid] int IDENTITY (1,1) PRIMARY KEY,
[Username] NVARCHAR(MAX) NULL,
[Password] NVARCHAR(MAX) NULL,
[Email] NVARCHAR(MAX) NULL,
[Name] NVARCHAR(MAX) NULL
It gives me the following error when I try to sign up:
System.Data.SqlClient.SqlException: 'An explicit value for the identity column in table 'Users' can only be specified when a column list is used and IDENTITY_INSERT is ON.'
For some reason it doesn't let me add to the values.