I have an inventory application that displays the information in datagridview after entering a part number in a textbox and clicking a search button. My question is, how do I count the rows that are displayed and put the count in a textbox? Below is my code to display the rows that relate to the part number entered.
private void searchPartbtn_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(partSearch.Text))
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "SELECT * FROM Inventory WHERE PartNumber='" + partSearch.Text + "'";
command.CommandText = query;
connection.Close();
OleDbDataAdapter db = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
db.Fill(dt);
dataGridFB.DataSource = dt;
}
catch (OleDbException ex)
{
MessageBox.Show(ex.Message);
connection.Close();
}
searchHide();
connection.Close();
}
}
dt.Rows.Countwhich gives you count.