LAST_INSERT_ID()

The LAST_INSERT_ID() function in a SELECT statement returns the last automatically generated item ID that was set by the most recent successful INSERT or CALL statement to a list or document library. The value only remains within the same SharePointConnection instance. The return type is Int32.

Syntax

SELECT LAST_INSERT_ID();

The LAST_INSERT_ID() function produces the same value as the LastInsertedId property of the SharePointCommand class.

Code examples

Using the LAST_INSERT_ID() function

using (var connection = new SharePointConnection(connectionString))
{
    connection.Open();
    using (var command = new SharePointCommand(@"INSERT INTO employees (name) VALUES ('Steve Watson')", connection))
    {
        command.ExecuteNonQuery();
    }
    using (var command = new SharePointCommand(@"SELECT LAST_INSERT_ID()", connection))
    {
        var lastInsertedId = (int)command.ExecuteScalar();
        Console.WriteLine("Steve's ID is:" + lastInsertedId);
    }
}

Code result

Steve's ID is:23


Skip Navigation Links.

Visa     MasterCard