【发布时间】:2011-05-06 10:58:55
【问题描述】:
我有一个 INSERT 查询,我希望数据库返回我刚刚插入的行的 ID。
sqlString = "INSERT INTO MagicBoxes (OwnerID, Key, Name, Permissions, Active, LastUpdated) VALUES (@OwnerID, @BoxKey, @BoxName, 0, 1, @Date) SET @ID = SCOPE_IDENTITY();";
cmd = new SqlCommand(sqlString, con);
cmd.Parameters.AddWithValue("@OwnerID", OwnerID);
cmd.Parameters.AddWithValue("@BoxKey", BoxKey);
cmd.Parameters.AddWithValue("@BoxName", BoxName);
cmd.Parameters.AddWithValue("@Username", Username);
cmd.Parameters.AddWithValue("@Date", DateTime.Now);
cmd.ExecuteNonQuery();
我目前有这个,我不确定接下来我需要做什么......
【问题讨论】:
-
无法得到你的问题,你想要刚刚插入的行的种子值吗?
标签: c# sql sql-server insert