我已经在表中插入了一行,我想获取它的ID并加上一个int并将其插入到该行中。

但我不知道如何获取它的ID。

这是插入代码:

objCommand.Connection = objConnection;
objCommand.CommandText = "INSERT INTO Moin " +
                         " (Title, TotalID, Code ) " +
                         "VALUES (@Title , @TotalID, @Code )";

最佳答案

objCommand.Connection = objConnection;
            objCommand.CommandText = "INSERT INTO Moin " +
                " (Title, TotalID, Code ) " +
                "VALUES (@Title , @TotalID, @Code ) SELECT SCOPE_IDENTITY()";
object id = objCommand.ExecuteScalar();

10-07 16:27