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:

  1. id || Int
  2. StartDate || Date Time
  3. 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

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -