同时搜索两个数据网格中的数据

时间:2013-07-26 22:00:34

标签: c# search rowfilter

我有两个数据网格,其中JMBGvlasnika与BrojSasije相同。

对于搜索,我使用此代码:

 DataView DV = new DataView(dbdt);
                    DV.RowFilter = String.Format("JMBGvlasnika LIKE '%{0}%'", textBox1.Text);
                    korisniciDataGridView.DataSource = DV;

加载表代码:

private void svikorisnici_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand(" SELECT * FROM Korisnici", konekcija);
            SqlCommand cmd1 = new SqlCommand(" SELECT * FROM vozilo", konekcija);
            try
            {
                SqlDataAdapter sda = new SqlDataAdapter();
                sda.SelectCommand = cmd;
                dbdt = new DataTable();
                sda.Fill(dbdt);
                BindingSource kbs = new BindingSource();

                kbs.DataSource = dbdt;
                korisniciDataGridView.DataSource = kbs;
                sda.Update(dbdt);


                SqlDataAdapter sda1 = new SqlDataAdapter();
                sda1.SelectCommand = cmd1;
                DataTable dbdt1 = new DataTable();
                sda1.Fill(dbdt1);
                BindingSource kbs1 = new BindingSource();

                kbs1.DataSource = dbdt1;
                voziloDataGridView.DataSource = kbs1;
                sda1.Update(dbdt1);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

问题是当我通过JMBGvlasnika搜索时,我只获得第一张表的搜索结果

图片链接http://ge.tt/999Igxm/v/0?c

如果我尝试这样做:

DataView DV1 = new DataView(dbd1t);
DV1.RowFilter = String.Format("JMBGvlasnika LIKE '%{0}%'", textBox1.Text);
voziloDataGridView.DataSource = DV1;

开始搜索我得到空的第二个表,如果我删除了我写的第二个表没有过滤。

有人可以帮我同时在两个数据网格中进行搜索吗?

0 个答案:

没有答案
相关问题