Reputation: 23
Userid
is auto incremented value and giving default as its value doesn't work
string inse = @"insert into registration (userid, firstname, lastname, day,
month, year, address, city, pincode,
state, country, phoneno, emailaddress)
values (DEFAULT, @firstname, @lastname, @day,
@month, @year, @address, @city, @pincode,
@state, @country, @phoneno, @emailaddress)";
SqlCommand cmd = new SqlCommand(inse, con);
cmd.Parameters.AddWithValue("@firstname", txtfname.Text);
cmd.Parameters.AddWithValue("@lastname", txtlname.Text);
..
etc
Upvotes: 2
Views: 120
Reputation: 113
Just don't add it at all in the query, if it's auto-incremented then the database will handle the ID.
Query that should work:
string inse = @"insert into registration(firstname,lastname,day,month,year,
address,city,pincode,state,country,phoneno,emailaddress)
values
(@firstname,@lastname,@day,@month,@year,@address,@city,@pincode,
@state,@country,@phoneno,@emailaddress)";
Upvotes: 2