How to insert values for Identity column directly?

phyllislemon

New Member
I am trying to insert values into the database through this UI. Below is the code. Now I want the ID column to take values directly (its the primary key & I have also set Identity on that column). Next, all the other values should be inserted into the corresponding columns in the database. Rt now whats happening is, the value from the Name textbox goes to the ID column & it sort of results in an off-by-one error. How can I acheive what I want?
dLeEf.png
\[code\] protected void btnRegister_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]); string strQuery = "Insert into AUser values ('"+ txtName.Text +"', '"+ txtEmailAddress.Text +"', '"+txtPassword.Text +"', '"+ ddlMobile.Text +"', '"+ ddlMobile.Text +"', '"+ txtMobileNumber.Text +"' )"; SqlCommand Cmd = new SqlCommand(strQuery,con); con.Open(); Cmd.ExecuteNonQuery();\[/code\]
vRzSs.png
 
Back
Top