gpt4 book ai didi

asp.net - SCOPE_IDENTITY() 不起作用

转载 作者:行者123 更新时间:2023-12-02 23:22:15 25 4
gpt4 key购买 nike

当我尝试通过 SQL Server 获取插入数据库的最后一个 ID 时,它返回 __Page。这是我的代码:

query = "INSERT INTO
seekers(name, sname, lname, status, gender, dob, major, experince,
email, password, phone, valid, city)
values (@name, @sname, @lname, @status ,@gender, @dob, @major,
@exp, @email, @password, @phone, 0, @city);
SELECT SCOPE_IDENTITY();";

// some code here related to parameters

command = new SqlCommand(query, connection);
int id = Convert.ToInt32(command.ExecuteScalar());

最佳答案

如果您只想SELECT,请使用OUTPUT

INSERT INTO seekers(name,sname,lname,status,gender,dob,major,experince,email,password,phone,valid,city)
OUTPUT INSERTED.IDENTITY_COL_NAME
values(@name,@sname,@lname,@status,@gender,@dob,@major,@exp,@email,@password,@phone,0,@city);

关于asp.net - SCOPE_IDENTITY() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12509197/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com