Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Combine to sql results in one datagridview

$
0
0

Hi everyone!

I have two search sql commands and I would like to get the result in one datagridview. How can i do this?

My search codes:

First - 

private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
                OleDbConnection conn = new OleDbConnection(connStr);
                OleDbDataAdapter da = new OleDbDataAdapter("Select * from [" + testcb.SelectedItem.ToString() + "$] where [" + addcb.SelectedItem.ToString() + "] = '" + addtb.Text + "'", conn);

                DataTable ds = new DataTable();
                da.Fill(ds);
                dataGridView2.DataSource = ds;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Second - 

 private void searchbtn_Click(object sender, EventArgs e)
        {
            try
            {
                string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
                OleDbConnection conn = new OleDbConnection(connStr);
                OleDbDataAdapter da = new OleDbDataAdapter("Select * from [" + testcb.SelectedItem.ToString() + "$] where [" + comboBox1.SelectedItem.ToString() + "] = '" + textBox5.Text + "'", conn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGridView2.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

I have one datagridview and would like to see total result of 2 requests in one(tables will be the same!)

Thanks a lot!

Sincerely,

Adil Aliyev


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>