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
OleDB Select Statement
提问by Harold
I have a search button in my program. What I want is every time I search I will type the lastname
and when the lastname
is equivalent to any lastname
in the database, the firstname
and the lastname
of the person will be displayed in a listbox
and 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
数据库中的任何时,此人的firstname
和lastname
将显示在 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);