Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
if we doesnot enter the id value than error is comes
previously the doesnt occurs but when i update the vs then it happens
give me solution plzzz please

What I have tried:

C#
try
      {

            SqlConnection con = new SqlConnection("Data Source=VIDYA\\SQLEXPRESS;Initial Catalog=EExamData;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand("insert into Signup(Name,Gender,Email,Password) values('" + name.Text + "','" + Gender + "','" + emailid.Text + "','" + passward.Text + "')", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            
            
            lbl_error.Text = "Successfully Registered";
        }
        catch(Exception ex)
        {
            Response.Write("Error" + ex);
        }


tableconsist of:id(primary key),name,gender,email_id,password
Posted
Updated 20-Apr-16 5:42am
v2
Comments

1 solution

You need to make the column an Identity column. Then it will automatically fill in a number for you. See IDENTITY (Property) (Transact-SQL)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900