1

我有这两个数据网格,其中 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;

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

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

4

0 回答 0