Problem
How to get same Items Exist in two Data tables in third data table by linq to sql and display in datagridview
in windows form application visual studio 2015.
Meaning I Have two datatables
First Data table is dt Get data from Excel .
Second is dtItems get data from sql server 2014 database .
I need when I have itemcode 12 and this item exist on two datatables
dt(display data from excel) AND dtItems (Display data from sql server)
show them in datagridview
if itemcode 12 exist on dt and dtItems display on datagridview .
so that how to get similar it Items between two datatable by linq to sql in datagridview .
- public DataTable ShowExcelData()
- {
- string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", txtpath.Text);
-
- OleDbConnection con = new OleDbConnection(connectionString);
-
-
- con.Open();
- DataTable dt = new DataTable();
-
- dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
-
- string SheetName = dt.Rows[0]["TABLE_NAME"].ToString();
-
-
- OleDbCommand com = new OleDbCommand();
- com.Connection = con;
-
- com.CommandText = @"SELECT [ItemCode],[ItemsName],[ItemAddress] FROM [" + SheetName + "] ";
- OleDbDataAdapter oledbda = new OleDbDataAdapter();
- oledbda.SelectCommand = com;
- DataSet ds = new DataSet();
- oledbda.Fill(ds);
- dt = ds.Tables[0];
- con.Close();
- return dt;
-
-
- }
- dt = ShowExcelData();
-
- public DataTable GetSqlItems()
- {
- string GetItems = @"select ItemCode,ItemsName,ItemAddress from Items";
-
-
- DataTable tbGetItems = DataAccess.ExecuteDataTable(GetItems );
- return tbGetItems ;
- }
- dtItems = GetSqlItems();