Hi, not sure what error you are getting but I think I see some problems with your code. You seem to be matching the wrong column in the following code:
Quote:
cmd2.CommandText = @"SELECT [Location] FROM [Barcodes] WHERE [Barcode] = '" + DGStock.Rows[i].Cells["Location"].Value + "'";
shouldn't the above be:
Quote:
cmd2.CommandText = @"SELECT [Location] FROM [Barcodes] WHERE [Location] = '" + DGStock.Rows[i].Cells["Location"].Value + "'";
and also you should not be using ExecuteNonQuery to select data from a table, its only used by insert, update and delete and similar commands:
Quote:
cmd2.ExecuteNonQuery();
it should be:
Quote:
OledbDataReader rdr= cmd2.ExecuteReader();
and then you should be able to access the right column from an index from the reader. Following which the following check :
Quote:
if (DGStock.Rows[i].Cells["Location"].Value == "[Location]")
would become this:
Quote:
if (DGStock.Rows[i].Cells["Location"].Value == rdr["Location"].ToString())
Overall i think the code could benefit from a little refactoring and tidying up as well. But do try these changes first and let us know if that solved your problm, if it doesn't i will delete my solution and we will re-think.