Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Two Different Server

server 1 : 192.168.99.111 - MySQL
Employee_id,name,address,manager_code - Table person
Server 2 : 192.168.99.112 - SQL
manager_code, Manager_fullname - Table Manager


Now, I want to display the information of two tables with different server in my gridview.
Like:
employee_id,name,manager_fullname.


Anyone help me to solve this Issue.
Posted
Updated 7-Feb-14 14:20pm
v3

1 solution

Use this as sample reference:

C#
using System.Linq;
using System.Data;
using System.Collections.Generic;
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable dtMysql = new DataTable();
            dtMysql = GetDataFromMysqlSource(); //your code
 

            DataTable dtSQL = new DataTable();
            dtSQL = GetDataFromSQLSource();  // your code
            
            List<EntityMySQL> lstMySQL = new List<EntityMySQL>();
            foreach (DataRow row in dtMysql.Rows)             
                lstMySQL.Add(new EntityMySQL() { Employee_ID = Convert.ToInt32( row["Employee_ID"]), Name = row["name"].ToString(), manager_code = row["manager_code"].ToString() });

            List<EntitySQL> lstSQL = new List<EntitySQL>();
            foreach (DataRow row in dtSQL.Rows)
                lstSQL.Add(new EntitySQL() {  manager_fullname = row["manager_fullname"].ToString(), manager_code = row["manager_code"].ToString() });

            var data = lstMySQL.Join(lstSQL, (k => k.manager_code), (k => k.manager_code), (mysql, sql) => new { employee_id = mysql.Employee_ID, name = mysql.Name, manager_fullname = sql.manager_fullname }).ToList();
            GridView1.DataSource = data;
            GridView1.DataBind(); 

        }
    }
   public class EntityMySQL 
    {
        public int Employee_ID { get; set; }
        public string Name { get; set; }
        public string manager_code { get; set; }
    }
   public class EntitySQL
    {
        public string manager_code { get; set; }
        public string manager_fullname { get; set; }
    }


}
 
Share this answer
 
Comments
Richard4 7-Feb-14 22:36pm    
Thank you KARTHIK this is very helpful.
Karthik_Mahalingam 8-Feb-14 0:34am    
Welcome Richard:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900