title: C# Merge Join DataTables (using unique id) Loaded by CSV Parser
body: <p>I am trying to merge and join two imported CSV files into one single DataTable. C# is new to me but I have done similar in PS and KSH many times before. </p>
  
  <p>The data loads fine and is output to console as ok as two seperate tables, but i can't figure out how to join the results of each ShowTable() using Primary Keys (wID,UserID) as the join condition.</p>
  
  <p>I tried to <code>return Table_SalesUserData; and return Table_WifiUserData;</code> that gives  <code>[ 'Form1.CreateTableWifi()' returns void, a return keyword must not be followed by an object expression ]</code> errors. </p>
  
  <p>I also tried to use : <code>DataSet setSalesWifi = new DataSet();</code> But in the <code>Button1_Click()</code> it throws <code>[  System.ArgumentNullException: ''column' argument cannot be null. Parameter name: column' ]</code> error.  </p>
  
  <p>Which I assume is because the .Columns for each is out of scope. </p>
  
  <p>The tables are created like below.  They are loaded by GenericParser (code work fine and is quite long so haven't posted) these are <code>InsertTableWifi(string srcFilePathWifi)</code> and <code>InsertTableSales(string srcFilePathSales)</code>.</p>
  
  <p>I think I'm ok to output the merged data when it works, just can't figure out how to join them into either a new DataTable or DataSet. </p>
  
  <p>Is there a simple way to merge the data with what i have?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.IO;
  using System.Text.RegularExpressions;
  using GenericParsing;
  
  namespace GenericParserv1._1._6
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
  
          }
          DataTable Table_SalesUserData = new DataTable("SalesUserData ");
          DataTable Table_WifiUserData = new DataTable("WifiUserData ");
          DataSet setSalesWifi = new DataSet();
  
      public void CreateTableSales()
          {
              DataColumn[] colsSales ={
                        new DataColumn("UserID",typeof(String)),
                        new DataColumn("Alias",typeof(String)),
                        new DataColumn("UserType",typeof(String)),
                        new DataColumn("AccountStatus",typeof(String)),
                        new DataColumn("ChgPasswdNxtLogin",typeof(String)),
                    };
              Table_SalesUserData.Columns.AddRange(colsSales);
              Table_SalesUserData.PrimaryKey = new DataColumn[] { Table_SalesUserData.Columns["UserID"] };
              setSalesWifi.Tables.Add(Table_SalesUserData);
              //return Table_SalesUserData ;
          }
  
          public void CreateTableWifi()
          {
  
              DataColumn[] colsWifi ={
                        new DataColumn("wID",typeof(String)),
                        new DataColumn("username",typeof(String)),
                        new DataColumn("fname",typeof(String)),
                        new DataColumn("lastname",typeof(String)),
                        new DataColumn("email",typeof(String)),
                        new DataColumn("empid",typeof(String)),
                        new DataColumn("lastlogintime",typeof(String))
                    };
  
              Table_WifiUserData.Columns.AddRange(colsWifi);
              Table_WifiUserData.PrimaryKey = new DataColumn[] { Table_WifiUserData.Columns["wID"] };
              setSalesWifi.Tables.Add(Table_WifiUserData);
              //return Table_WifiUserData ;
          }
  
          public void CreateTableReport()
          {
  
              DataColumn[] colsMerge ={
                        new DataColumn("wID",typeof(String)),
                        new DataColumn("username",typeof(String)),
                        new DataColumn("fname",typeof(String)),
                        new DataColumn("lastname",typeof(String)),
                        new DataColumn("email",typeof(String)),
                        new DataColumn("empid",typeof(String)),
                        new DataColumn("lastlogintime",typeof(String)),
                        new DataColumn("UserID",typeof(String)),
                        new DataColumn("Alias",typeof(String)),
                        new DataColumn("UserType",typeof(String)),
                        new DataColumn("AccountStatus",typeof(String)),
                        new DataColumn("ChgPasswdNxtLogin",typeof(String)),
                    };
  
              Table_MergeUserData.Columns.AddRange(colsMerge);
              Table_MergeUserData.PrimaryKey = new DataColumn[] { Table_MergeUserData.Columns["wID"] };
          }
  
          private static void ShowTable(DataTable table)
          {
              foreach (DataColumn col in table.Columns)
              {
                  Console.Write("{0,-14}", col.ColumnName);
              }
              Console.WriteLine();
  
              foreach (DataRow row in table.Rows)
              {
                  foreach (DataColumn col in table.Columns)
                  {
                      if (col.DataType.Equals(typeof(DateTime)))
                          Console.Write("{0,-14:d}", row[col]);
                      else if (col.DataType.Equals(typeof(Decimal)))
                          Console.Write("{0,-14:C}", row[col]);
                      else
                          Console.Write("{0,-14}", row[col]);
                  }
                  Console.WriteLine();
              }
              Console.WriteLine();
          }
  
        private void Button1_Click(object sender, EventArgs e)
          {
              string srcFilePathWifi = @"c:\WifiUserData.csv";
              string srcFilePathSales = @"c:\SalesUserData.csv";
  
              CreateTableSales();
              InsertTableSales(srcFilePathSales);
  
              CreateTableWifi();
              InsertTableWifi(srcFilePathWifi);
  
              ShowTable(Table_WifiUserData);
              ShowTable(Table_SalesUserData);
  
              // Set the relations between the tables and create the related constraint.
              setSalesWifi.Relations.Add("Table_WifiUserData", Table_SalesUserData.Columns["wID"], Table_SalesUserData.Columns["UserID"], true);
  
          }
  
      }
  }
  
  </code></pre>
  
  <p>WifiUserData.csv:</p>
  
  <pre><code>wID           username      fname         lastname      email         empid         lastlogintime 
  msmith        marysmith     mary          smith         marysmith@company.com10001         24/01/2019 14:00
  jbloggs       joebloggs     joe           bloggs        joebloggs@company.com10002         10/01/2019 9:00
  pgolightly    petergolightlypeter         golightly     petergolightly@company.com10003         20/01/2019 17:00
  rrabbit       rogerrabbit   roger         rabbit        rogerrabbit@company.com10004         1/02/2019 14:00
  </code></pre>
  
  <p>SalesUserData.csv:</p>
  
  <pre><code>UserID        Alias         UserType      AccountStatus ChgPasswdNxtLogin
  msmith        mary smith    Manager       No            No            
  jbloggs       joe bloggs    Standard      No            No            
  pgolightly    peter golightlyJunior        No            No            
  rrabbit       roger rabbit  Standard      No            No   
  </code></pre>
  
  <p>What I am aiming for:</p>
  
  <pre><code>UserID  Alias   UserType    AccountStatus   ChgPasswdNxtLogin   username    fname   lastname    email   empid   lastlogintime
  msmith  mary smith  Manager No  No  marysmith   mary    smith   marysmith@company.com 10001 24/01/2019 14:00
  jbloggs joe bloggs  Standard    No  No  joebloggs   joe bloggs  joebloggs@company.com 10002 10/01/2019 9:00
  pgolightly  peter golightly Junior  No  No  petergolightly  peter   golightly   petergolightly@company.com 10003    20/01/2019 17:00
  rrabbit roger rabbit    Standard    No  No  rogerrabbit roger   rabbit  rogerrabbit@company.com 10004   1/02/2019 14:00
  </code></pre>