Skip to content Skip to sidebar Skip to footer

Linq To Sql - How To Find The Value Of The Identity Column After Insertonsubmit()

I am using LINQ to SQL to insert simple data into a table WITHOUT a stored procedure. The table has a Primary Key ID column, which is set as an IDENTITY column in both SQL Server

Solution 1:

here is a simple code snippet

Dim odb AsNew DataClassesDataContext
            Dim tst AsNew test
            tst.name = "abcd"
            odb.tests.InsertOnSubmit(tst)
            odb.SubmitChanges()
            Response.Write("id:" + tst.id.ToString)

so, basically the object you used in InsertOnSubmit will get the identity field populated after the record has been created in the database

Post a Comment for "Linq To Sql - How To Find The Value Of The Identity Column After Insertonsubmit()"