2013-04-27 62 views
-1

我從ComboBox中選擇了DataRow(dr1),並且我想從選定的DataRow中統計行。從特定的DataRow計數行

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     string searchfor = comboBox1.Text; 
     int results = 0; 
     DataRow[] returnedrows; 

     returnedrows = ds1.Tables["workers"].Select("first_name='" + searchfor + "'"); 

     results = returnedrows.Length; 

     if (results > 0) 
     { 
      DataRow dr1; 
      dr1 = returnedrows[0]; 

      textBox1.Text = dr1[1].ToString(); textBox2.Text = dr1[2].ToString(); 
      textBox3.Text = dr1[3].ToString(); textBox4.Text = dr1[4].ToString(); 
      textBox5.Text= dr1[5].ToString(); 

     } 
     else 
     { 
      MessageBox.Show("no such records"); 
     } 
+0

PLZ嘗試寫你的問題在身體而不是標題。 – Sachin 2013-04-27 11:49:54

+0

你想實現什麼? – 2013-04-27 12:09:48

回答

2

什麼類型的對象是表?它是一個數據表?嘗試這樣的:

var result = ds1.Tables["workers"].Where(t => t.first_name == searchfor); 

int resultCount = result.Count();