title: C#/DataTable/DataGrid/SQL - How can I insert Params into a stored procedure from DataGridView
body: <p>Thank you for taking you time to read this. Basically what I am trying to do is return details on [Issues] that gets pulled from the DB via a stored procedure</p>
  
  <p>There are 2 parameters, <code>[IssueNo]</code> and <code>[LineNo]</code>. When I click on a button the program needs to return the details eg: ItemName, Code etc for each DataGridRow that I select, BUT what it currently does is return the LAST [Issues] details instead of the one I am selecting in the grid. </p>
  
  <p>I know that my stored procedure is correct but somewhere in my C# code the parameters are not getting the value for every row I select. Only ONE and its still the wrong one</p>
  
  <pre><code>foreach (DataRow dr in dataGridView2.SelectedRows)
  {
      IssueNo = Convert.ToInt32(dr[0].ToString());
      TranLineNo = Convert.ToInt32(dr[1].ToString()); 
  }
  
  detailsCmd.Parameters.AddWithValue("IssueNo", IssueNo);
  detailsCmd.Parameters.AddWithValue("TranLineNo", TranLineNo);
  DetailsIssue details1 = new DetailsIssue();
  
  SqlDataAdapter Idetails = new SqlDataAdapter(detailsCmd);
  Idetails.Fill(detailsReturned);
  
  details1.dgvIssuesDetail.DataSource = detailsReturned;
  details1.Show();
  </code></pre>
  
  <p>That is the code for finding the parameters for the stored procedure. </p>
  
  <p><a href="https://prnt.sc/qybxvs" rel="nofollow noreferrer">https://prnt.sc/qybxvs</a> here is what the app looks like, the red is the row selected and the the details buttons clicked once clicked it passes the IssueNo and the TranLineNo in black to the stored procedure which then returns the Details for the Issue that's selected. it returns the correct data idea but for the wrong issue. And if I select multiple rows it still only returns one</p>
  
  <p>If you need any other additional information please feel free to ask. I patiently await your reply</p>