Home > DeveloperSection > Forums > How To Use Two Queries One Datagrid
Demir ACAR
Demir ACAR

Total Post:11

Points:77
Posted on    September-03-2014 6:19 AM

 C# C# 
Ratings:


 0 Reply(s)
 745  View(s)
Rate this:
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 conn2 = 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();

}

}

}



Don't want to miss updates? Please click the below button!

Follow MindStick