The SelectAll method does something else. This method selects all cells.
You should read the values with a code similar to the code below
It should be noted that parentheses are also required in your SQL query, which I added in the GetBoxNumbersAsString method.
private string GetBoxNumbersAsString(bool IncludeParentheses = true)
{
var BoxNumbers = GetListOfCellValues(0);
var BoxNumbersAsString = string.Join(", ", BoxNumbers);
if (IncludeParentheses)
BoxNumbersAsString = "(" + BoxNumbersAsString + ")";
return BoxNumbersAsString;
}
private List<int> GetListOfCellValues(int ColumnIndex = 0)
{
var ListOfCellValues = new List<int>();
foreach (DataGridViewRow Row in dataGridView1.Rows)
{
var Value = Row.Cells[ColumnIndex].Value;
if (Value != null)
// The last row may be empty in edit mode!
ListOfCellValues.Add(int.Parse(Value.ToString()));
}
return ListOfCellValues;
}
Your SQL query should look like the following:
"SELECT NOTE FROM TABLE WHERE BOX_NUMBER IN " + GetBoxNumbersAsString(true)