possible to join table A in sql server and table B in mysql with c#.Net (for example linq, or others)

Martin Wang 101 Reputation points
2022-05-13T07:49:12.17+00:00

hi, is it possible to join table A in sql server and table B in mysql with c#.Net(for example linq, or others)

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
710 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,644 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,281 Reputation points Microsoft Vendor
    2022-05-13T09:45:32.537+00:00

    @Martin Wang , Welcome to Microsoft Q&A, you could convert two tables in database to two datatables separately.

    I make a code example and you could have a look.

     private void button1_Click(object sender, EventArgs e)  
            {  
               DataTable table1 = GetDataTable1();  
               DataTable table2 = GetDataTable2();  
               var results = from t1 in table1.AsEnumerable()  
                              join t2 in table2.AsEnumerable() on t1.Field<string>("StuName") equals t2.Field<string>("StuName")  
                             select new  
                              {  
                                  StuName = t1.Field<string>("StuName"),  
                                 SubjectName = t2.Field<string>("SubjectName"),  
                                 Score = t2.Field<int>("Score"),  
                                 StuAge = t1.Field<int>("StuAge")  
      
                             };  
                dataGridView1.DataSource = results.ToList() ;  
      
            }  
            public DataTable GetDataTable1()  
            {  
                string connstr = "connstr";  
                SqlConnection connection = new SqlConnection(connstr);  
                connection.Open();  
                string sql = "select * from StuInfo ";  
                DataTable table1 = new DataTable();  
                SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);  
                adapter.Fill(table1);  
                connection.Close();  
                return table1;  
            }  
      
            public DataTable GetDataTable2()  
            {  
                string connstr = "connstr";  
                MySqlConnection connection = new MySqlConnection(connstr);  
                connection.Open();  
                string sql = "select * from ScoreInfo ";  
                DataTable table2 = new DataTable();  
                MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);  
                adapter.Fill(table2);  
                connection.Close();  
                return table2;  
            }  
    

    Tested result:

    201762-image.png

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments