title: Get First Tables Inserted Values to Second table
body: <p>I have two queries with transaction scope. I need to insert first tables inserted value to my detail table. In here my <code>NewsId</code> in first table is the primary key and an auto-incremented one. I need to insert that id into the second table (<code>Detail</code> table)</p>
  
  <pre><code>// Some code here
  
  transaction = con.BeginTransaction();
  
  // NewsId is the primary key and auto-incremented. I need to retrieve 
  // that value and insert it into the second table 
  string query1 = "INSERT INTO ABC(NewsCode, Comment) VALUES (@NewsCode, @Comment)"; 
  cmd = db.GetSqlStringCommand(query1);
  cmd.Transaction = transaction;
  
  db.AddInParameter(cmd, "NewsCode", DbType.Int32, News.NewsCode);
  db.AddInParameter(cmd, "Comment", DbType.String,News.Comment);
  
  db.ExecuteNonQuery(cmd, transaction);
  
  foreach (var item in NewsTotal.items)
  {
      // I'm going to insert into the `Detail` table and I need the 
      // previously inserted table's NewsId
      string newsItemsQuery = @"INSERT INTO [dbo].[TBL_T_NewsItems] ([NewsId], [ItemId])
                                VALUES (@NewsId, @Comment)";
  
      // some code here
  }
  </code></pre>