When I try to update the selected row I get a error:
'Index was outside the bounds of the array.'
where I declare the DataRow dr = ...
.
Is this the correct way of doing it?
the ind value updates as i click on other rows in the data grid.
EDIT
So I found the problem, the "index" is using the serial numbers in the DB, which are like this 6066123400654.. so obviously that is why I got the error. I changed the serial number to 0,1,2,3,4 respectively and now I can update fine, but the question now is how do I use the real serial numbers as the index?? I'm really confused now.
public bool UpdateComponents(List<int> index, DataTable Data)
{
foreach (int ind in index)
{
DataRow dr = Data.Select("SerialNumber ="+ ind.ToString())[0];
{
using (SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["SHS_CON"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("usp_UpdateComponent", sqlcon))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@serialnumber", dr[0]);
cmd.Parameters.Add("@manufacturer", dr[1]);
cmd.Parameters.Add("@model", dr[2]);
cmd.Parameters.Add("@description", dr[3]);
cmd.Parameters.Add("@price", dr[4]);
sqlcon.Open();
cmd.ExecuteNonQuery();
sqlcon.Close();
}
}
}
}
return true;
}