[英]How to insert other values into database in Visual Studio when there is an ID auto incremented
Userid
is auto incremented value and giving default as its value doesn't work Userid
是自动递增的值并给出默认值,因为它的值不起作用
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等等
Just don't add it at all in the query, if it's auto-incremented then the database will handle the ID.只是不要在查询中添加它,如果它是自动递增的,那么数据库将处理 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)";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.