问题描述
大家好,我有这个数据库 []
i想要搜索姓氏史密斯的婴儿 和他们的性别是男性
i有一个用于输入姓氏的文本框和一个用于选择性别的组合框和一个用于获取结果的按钮,当我按按钮它只获取名称而忽略性别条件。
这是我的代码:
Hello guys , i have this database https://ibin.co/2phSKY8PfVSs.png[^]
i want to search for babies with last name "Smith" and their gender is "Male"
i have a textbox for entering lastname and a combobox to choose gender and a button to get the result, when i press the button it only gets the name and neglect the gender condition.
here is my code :
private DataTable tb1 = new DataTable();
private DataTable GetTbb()
{
// DataTable tb1 = new DataTable();
string conectingstrng = ConfigurationManager.ConnectionStrings["hsmcntr.Properties.Settings.tbbConnectionString"].ConnectionString;
using (OleDbConnection con = new OleDbConnection(conectingstrng))
{
using (OleDbCommand cmd = new OleDbCommand("Select *from Table1", con))
{
con.Open();
OleDbDataReader reader = cmd.ExecuteReader();
tb1.Load(reader);
}
}
return tb1;
}
private void GETRSLT(string Nme, string Gndr, ComboBox nme, ComboBox gndr)
{
DataView dvtble = tb1.DefaultView;
dvtble.RowFilter = Nme + "Like '%" + nme.SelectedItem + "%'" + Gndr + "Like '%" + gndr.SelectedItem + "%'";
}
private void button1_Click(object sender, EventArgs e)
{
GETRSLT("Nme","Gndr",textbox1,combobox1)}
我的尝试:
在我的脑海中尝试过但无济于事。
搜索了YouTube和Google,但没有找到与我有关的任何内容问题。
What I have tried:
Tried everthing in my mind but to no avail.
searched YouTube and google and didn't find anything related to my question.
推荐答案
dvtble.RowFilter = Nme + "Like '%" + nme.SelectedItem + "%'" + " AND " + Gndr + "Like '%" + gndr.SelectedItem + "%'";
在这里你会找到一个很好的总结过滤器语法:
[]
我希望它有所帮助。 />
喜欢运算符之前还缺少空格
Here you will find a nice summary about filter Syntax:
DataView RowFilter Syntax [C#][^]
I hope it helps.
There are also missing spacesbefore "Like" operator
dvtble.RowFilter = Nme + " Like '%" + nme.SelectedItem + "%'" + " AND " + Gndr + " Like '%" + gndr.SelectedItem + "%'";
这篇关于数据库多个搜索条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!