I'm want to join 2 table from access database and Microsoft SQL Server 2008 In microsoft visual studio 2008. Display join data in datagridview.

You have to qualifying the column names. eg. DatabaseName.TableName.Column_Name.

Name Space

using System.Data.SqlClient;

Connection string

connString = "Data Source = .\SQL2005;Initial Catalog= lianpiaudatabas;Integrated Security = True";

 try
            {
                DataTable objDT = new DataTable();
               

                SqlConnection objCon = new SqlConnection(conn);
                objCon.Open();

                SqlDataAdapter objDA = new SqlDataAdapter("select * from Table1 Inner join table2 on Table1.table1ID=Table2.Table2ID ",objCon);
                                objDA.Fill(objDT);
                                objCon.Close();

                               this.dataGridView1.DataSource = objDT;

            }
            catch (Exception ex)
            {
                MessageBox.Show("The Systems generated following error: " + ex.Message);
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.