HOW TO USE TWO QUERIES ONE DATAGRID

Demir ACAR

Total Post:11

Points:77
Posted by  Demir ACAR
C# 
C#
 1158  View(s)
Ratings:
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();
}
}
}

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!