c# - Pull on insert the auto increment id -
I am using a SQL Server ( .mdf
) database with C # and I want to enter automatic increment ID
At this time I have a table with 3 cells:
- id || Int
- StartDate || Date Time
- Gamemode || At the code level, I am not including the ID cell, the installation of the database takes care of it:
db.TblGames .inetombed (new TblGame {StartDate = DateTime.Now, GameMode = gm. ToString ()}); Db.SubmitChanges ();
Any ideas?
I take it that you are using LINQ to SQL auto-generated ID After TblGame must be in the instance. Submit ()
Return the TblGame example to obtain it, such as:
var game = new TblGame {StartDate = DateTime.Now, GameMode = gm.ToString () }; Db.TblGames.InsertOnSubmit (game); Db.SubmitChanges (); Var id = game.Id;
Comments
Post a Comment