ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275.4k

How to get same Items Exist in two Datatables in third datat

Sep 24 2018 7:54 PM

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 .
  1. public DataTable ShowExcelData()  
  2.         {  
  3.             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);  
  4.   
  5.             OleDbConnection con = new OleDbConnection(connectionString);  
  6.   
  7.   
  8.             con.Open();  
  9.             DataTable dt = new DataTable();  
  10.   
  11.             dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  12.   
  13.             string SheetName = dt.Rows[0]["TABLE_NAME"].ToString();  
  14.   
  15.   
  16.             OleDbCommand com = new OleDbCommand();  
  17.             com.Connection = con;  
  18.              
  19.             com.CommandText = @"SELECT  [ItemCode],[ItemsName],[ItemAddress] FROM  [" + SheetName + "] ";  
  20.             OleDbDataAdapter oledbda = new OleDbDataAdapter();  
  21.             oledbda.SelectCommand = com;  
  22.             DataSet ds = new DataSet();  
  23.             oledbda.Fill(ds);  
  24.             dt = ds.Tables[0];  
  25.             con.Close();  
  26.             return dt;  
  27.   
  28.   
  29.         }  
  30. dt = ShowExcelData();  
  31.   
  32.  public DataTable GetSqlItems()  
  33.         {  
  34.             string GetItems = @"select ItemCode,ItemsName,ItemAddress from Items";  
  35.   
  36.   
  37.            DataTable tbGetItems = DataAccess.ExecuteDataTable(GetItems );  
  38.             return tbGetItems ;  
  39.         }  
  40. dtItems = GetSqlItems();  
 

Answers (1)