繁体   English   中英

当 ID 自动递增时,如何在 Visual Studio 中将其他值插入到数据库中

[英]How to insert other values into database in Visual Studio when there is an ID auto incremented

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);
.. 

等等

只是不要在查询中添加它,如果它是自动递增的,那么数据库将处理 ID。

应该工作的查询:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM