PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
How to get same Items Exist in two Datatables in third datatable-VBForums
Results 1 to 2 of 2

Thread: How to get same Items Exist in two Datatables in third datatable

  1. #1

    Thread Starter
    Join Date
    Apr 2018

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


    How to get same Items Exist in two Data tables in third data table by linq 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);
                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();
                dt = ds.Tables[0];
                return dt;
    dt = ShowExcelData();
     public DataTable GetSqlItems()
                string GetItems = @"select ItemCode,ItemsName,ItemAddress from Items";
               DataTable tbGetItems = DataAccess.ExecuteDataTable(GetItems );
                return tbGetItems ;
    dtItems = GetSqlItems();

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: How to get same Items Exist in two Datatables in third datatable

    This will create a new DataTable containing all the rows from 'table1' with an ID that is also present in 'table2':
    csharp Code:
    1. var table3 = table1.AsEnumerable()
    2.                    .Where(row => table2.Rows.Find(row["ID"]) != null)
    3.                    .CopyToDataTable();
    Modify that as you need and then bind the result to your grid.
    Last edited by jmcilhinney; Sep 24th, 2018 at 09:18 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width