1

我的程序中有一个搜索按钮。我想要的是每次搜索时我都会输入lastname和 当lastname等于lastname数据库中的任何时,人的firstnamelastname将显示在 a 中listbox,每当我单击结果时listbox,将显示该人的详细信息在textboxes. 问题是当有相同姓氏的人时,他们的名字是唯一列出的,但是当我点击名字时,相同的细节会出现在textboxes.

请帮忙。

这是我的代码:

    connection.Open();
    OleDbCommand select = new OleDbCommand();
    select.Connection = connection;
    select.CommandText = "Select * From Accounts Where Lastname  = '" + searchtb.Text + "'";
    OleDbDataReader reader = select.ExecuteReader();
    while (reader.Read())
    {
        listBox1.Items.Add(reader[1].ToString() + "," + reader[2].ToString());
    }
    connection.Close();
4

2 回答 2

2

您在此代码中没有任何错误,您的错误可能在您的 listbox_events 上。

显示列表框部分的代码。

于 2013-03-01T02:27:19.617 回答
0
 cFat_items2 = new OleDbDataAdapter("
      SELECT COUNT(Fat_Items.i_num) AS Count_i_num, Fat_Items.i_num, g.i_num 
      FROM Fat_Items INNER JOIN Fat_Items AS g ON Fat_Items.fat_nr = g.fat_nr 
      WHERE Fat_Items.i_num = '" + this.kLDataSet.Fat_Items.Rows[i].ItemArray[0].ToString() + "' 
      AND g.i_num = '" + this.kLDataSet.Fat_Items.Rows[j].ItemArray[0].ToString() + "' 
      GROUP BY Fat_Items.i_num, g.i_num HAVING COUNT(Fat_Items.i_num)>='" + Support + "'", con);

 cFat_items2.Fill(dFat_items2);
于 2016-05-03T08:39:41.937 回答