Demir Acar

Demir Acar

  • NA
  • 98
  • 25.3k

how to use two queries one datagrid

Sep 3 2014 8:57 AM
I have 2 server and 2 database ,  how to query 2 databases that localated different place and collect the result one datagrid .

 

for (int ii = 0; i < gridView1.RowCount; i++)

                {

                    SqlConnection conn = new SqlConnection(@"Data Source='" + tb6 + "';Initial Catalog='" + tb7 + "';user='" + tb8 + "';pwd='" + tb9 + "'");

                    SqlConnection conn = new SqlConnection(@"Data Source='" + tb1 + "';Initial Catalog='" + tb2 + "';user='" + tb3 + "';pwd='" + tb4 + "'");

                    SqlCommand cmd = new SqlCommand("SELECT ID AS REF ARACTIPI AS TIP,ARACADI AS ADI,MARKA AS MARKA FROM ARACBILGILER", conn);

                    DataTable tablo = new DataTable();

                    conn.Open();

                    conn2.Open();

                    SqlDataReader oku = cmd.ExecuteReader();

                    tablo.Load(oku);

                    SqlCommand cmd2 = new SqlCommand("SELECT DURUMU AS ARAC_DURUMU FROM ARACDB WHERE ID='" + gridView1.GetDataRow(i)["REF"] + "'", conn2);

                    SqlDataReader oku2 = cmd2.ExecuteReader();

                    tablo.Load(oku2);

                    gridControl1.DataSource = tablo;

conn.Close();

conn2.Close();

}

}

}


Answers (2)