计算特定DataRow中的行

时间:2013-04-27 11:47:29

标签: c#

我从ComboBox中选择了DataRow(dr1),我想计算选定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");
        }

1 个答案:

答案 0 :(得分:2)

桌子是什么类型的对象?它是DataTable吗?尝试类似:

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

int resultCount = result.Count();