CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
private void btnDisplayMakes_Click(object sender, EventArgs e)
{
// Build a filter based on user input.
string filterStr = string.Format("Make= '{0}'", txtMakeToView.Text);
// Find all rows matching the filter.
DataRow[] makes = inventoryTable.Select(filterStr);
if (makes.Length == 0)
MessageBox.Show("Sorry, no cars...", "Selection error!");
else
{
string strMake = "";
for (int i = 0; i < makes.Length; i++)
{
// From the current row, get the PetName value.
strMake += makes[i]["PetName"] + "\n";
}
// Show the names of call cars matching the specified Make.
MessageBox.Show(strMake,
string.Format("We have {0}s named:", txtMakeToView.Text));
}
}
Here, you begin by building a simple filter based on the value in the associated TextBox. If you
specify BMW, your filter looks like this:
Make = 'BMW'
When you send this filter to the Select() method, you get back an array of DataRow types that
represent each row that matches the filter (see Figure 22-9).
884