how to get the last record number after inserting record to database in access

前端 未结 5 715
[愿得一人]
[愿得一人] 2021-02-05 21:40

i have database in access with auto increase field (ID).

i insert record like this (in C#)

SQL = \"insert into TermNumTbl (DeviceID,IP) valu         


        
5条回答
  •  再見小時候
    2021-02-05 22:15

    I guess you could even write an extension method for OleDbConnection...

    public static int GetLatestAutonumber(
        this OleDbConnection connection)
    {
        using (OleDbCommand command = new OleDbCommand("SELECT @@IDENTITY;", connection))
        {
            return (int)command.ExecuteScalar();
        }
    }
    

提交回复
热议问题