0

How do i get the value of emp_id([emp_id] [int] IDENTITY(1,1) NOT NULL) from the command below after it has been executed.

 db.Database.ExecuteSqlCommand("INSERT INTO emptable ( emp_namefirst, emp_namemiddle) values ( {0},{1})", NewEmployeeModel.emp_namefirst, NewEmployeeModel.emp_namemiddle);
anatp_123
  • 43
  • 6
  • 3
    Alt, stop here and before continuing see what an Sql Injection is – Steve Feb 01 '19 at 21:30
  • 1
    You can't get it from that query. You must select `@@SCOPE_IDENTITY` or better yet use `OUTPUT inserted.emp_id` (which you can google). None of that will matter if someone sql injects your database though, so also google `SqlParameter`. – Crowcoder Feb 01 '19 at 21:38
  • 1
    Possible duplicate of [Execute Insert command and return inserted Id in Sql](https://stackoverflow.com/questions/18373461/execute-insert-command-and-return-inserted-id-in-sql) – mjwills Feb 01 '19 at 23:24

0 Answers0