使用mysql在datagridview中进行高级排序

所以我用这样的复选框做了简单的搜索:
enter image description here
这是 sort 按钮的代码:

private void sort_btn_Click(object sender, EventArgs e)
        {
            if (cntr_check.Checked == true && pos_check.Checked == true)
            {
                var query = from o in this.leodata.main
                            where o.country.Contains(cntr_combo.Text) && o.position.Contains(pos_combo.Text) && o.price <= price_bar.Value
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }
            else if (cntr_check.Checked == true && pos_check.Checked == false)
            {
                var query = from o in this.leodata.main
                            where o.country.Contains(cntr_combo.Text) && o.price <= price_bar.Value
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }
            else if (cntr_check.Checked == false && pos_check.Checked == true)
            {
                var query = from o in this.leodata.main
                            where o.position.Contains(pos_combo.Text) && o.price <= price_bar.Value
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }
            else
            {
                var query = from o in this.leodata.main
                            where o.price <= price_bar.Value
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }

        }

现在我需要进行高级搜索:
enter image description here
我试着这样做:

private void button1_Click(object sender, EventArgs e)
        {
            if (spain_check.Checked == true)
            {
                var query = from o in this.leodata.main
                            where o.country.Contains(spain_check.Text)
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }
            if (france_check.Checked == true)
            {
                var query = from o in this.leodata.main
                            where o.country.Contains(france_check.Text)
                            select o;
                mainBindingSource.DataSource = query.ToList();
            }
        }

其中 spain_checkfrance_check 是我的复选框 . 我有一个想法,我将检查每个chechboxes和如果 Checked == true 然后我将只是从mysql添加新行 . 但它不断更新我的表而不是添加新行 .

我该怎么做?

回答(0)