C# OleDB 选择语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15149220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 14:16:08  来源:igfitidea点击:

OleDB Select Statement

c#.netwinformsoledb

提问by Harold

I have a search button in my program. What I want is every time I search I will type the lastnameand when the lastnameis equivalent to any lastnamein the database, the firstnameand the lastnameof the person will be displayed in a listboxand whenever I click on the result in the listbox, the person's details will be displayed in the textboxes. The problem is when there are persons with same surname, their names are listed uniquely but when I click on the name, same details appear in the textboxes.

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

Please help.

请帮忙。

Here's my code:

这是我的代码:

    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();

采纳答案by Red Gabanan

You dont have any error in this code, Your error can possibly be on your listbox_events.

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

Show your codes for the listbox part.

显示列表框部分的代码。

回答by marwa

 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);