I'd get MySql data into datatable1, then i'd get Excel data into datatable2. Then i'd join them on key field and finally - display in a datagridview component.
public static DataTable ReadMySqlData(string myConnString, string mySelectQuery)
{
DataTable dt = new DataTable();
using(MySqlConnection myConnection = new MySqlConnection(myConnString))
using (MySqlCommand myCommand = new MySqlCommand(mySelectQuery,myConnection))
{
myConnection.Open();
using(MySqlDataReader myReader= myCommand.ExecuteReader())
dt.Load(myReader);
myConnection.Close();
}
return dt;
}
Use the same way to fetch Excel Data. Note: replace MySql objects with OlDb objects.
To get common data, you can use Linq:
DataTable MySqlDt = ReadMySqlData(..., ...);
DataTable ExcelDt = ReadExcelData(..., ...);
var commonData = (from md in MySqlDt.AsEnumerable()
join ed in ExcelDt.AsEnumerable() on md.Field<int>("ID") equals ed.Field<int>("EmployeeID")
select new
{
ID = md.Field<int>("ID"),
Name = md.Field<string>("Name"),
SurName = md.Field<string>("SurName"),
Phone = ed.Field<string>("Phone")
}).ToList();
)
DataGridView1.DataSource = commonData;
Good luck!