我试图使用listBox来选择搜索, 但我不能在LINQ中使用字符串si,我不知道如何使用它, 我制作了这段代码,但不知道如何使用si。
var db = new DataClasses1DataContext();
int selectedIndex = listBox1.SelectedIndex;
string si = "";
if (selectedIndex == 0) si = "id" ;
if (selectedIndex == 1) si = "name";
if (selectedIndex == 2) si = "sex";
if (selectedIndex == 3) si = "address";
if (selectedIndex == 4) si = "phone";
if (selectedIndex == 5) si = "web";
var qsearch = db.users.Where(c => c.[i want use si in this place].Contains(textBox7.Text));
dataGridView1.DataSource = qsearch;
答案 0 :(得分:0)
为什么不在每个if
语句中设置查询
switch (selectedIndex)
{
case 0:
dataGridView1.DataSource = db.users.Where(u => u.Id.Contains(...));
break;
....
}