Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to combine 2 LINQ dictionaries into 1?
    text
    copied!<p>I have 2 excel files that I have converted into lists. The 1st file has a complete list of all items that I need. However, the 2nd list has a small list of items that need to be changed in the 1st list. Here's how my 1st list is constructed:</p> <pre><code>IEnumerable&lt;ExcelRow&gt; queryListA = from d in datapullList select new ExcelRow { Company = d.GetString(0), Location = d.GetString(1), ItemPrice = d.GetString(4), SQL_Ticker = d.GetString(15) }; </code></pre> <p>The 2nd list is constructed in a very similar way:</p> <pre><code>IEnumerable&lt;ExcelRow&gt; queryListB = from dupes in dupespullList select new ExcelRow { Company = d.GetString(0), Location = d.GetString(1), NewCompany = d.GetString(4) }; </code></pre> <p>So, if there is a company from a particular location in 1st list that matches 2nd list, then the company gets changed to the newcompany name.</p> <p>Then, my final list should have everything in 1st list but with the changes specified from 2nd list. </p> <p>I've been struggling with this for a few days now. Let me know if you need more details.</p> <p>[Update:] I'm pretty new to LINQ and C#. I've found this code on the web regarding Excel reader for Office 2003. How can I create the 1 list (stated above) from all the following classes? My ExcelRow class:</p> <pre><code>class ExcelRow { List&lt;object&gt; columns; public ExcelRow() { columns = new List&lt;object&gt;(); } internal void AddColumn(object value) { columns.Add(value); } public object this[int index] { get { return columns[index]; } } public string GetString(int index) { if (columns[index] is DBNull) { return null; } return columns[index].ToString(); } public int Count { get { return this.columns.Count; } } } </code></pre> <p>My ExcelProvider class:</p> <pre><code>class ExcelProvider : IEnumerable&lt;ExcelRow&gt; { private string sheetName; private string filePath; private string columnName1; private string columnName2; private List&lt;ExcelRow&gt; rows; public ExcelProvider() { rows = new List&lt;ExcelRow&gt;(); } public static ExcelProvider Create(string filePath, string sheetName, string columnName1, string columnName2) { ExcelProvider provider = new ExcelProvider(); provider.sheetName = sheetName; provider.filePath = filePath; provider.columnName1 = columnName1; provider.columnName2 = columnName2; return provider; } private void Load() { string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties= ""Excel 8.0;HDR=YES;IMEX=1"""; connectionString = string.Format(connectionString, filePath); rows.Clear(); using (OleDbConnection conn = new OleDbConnection(connectionString)) { try { conn.Open(); using (OleDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = string.Format("SELECT * FROM [{0}$] WHERE {1} IS NOT NULL AND {2} &lt;&gt; \"{3}\"", sheetName, columnName1, columnName2, null); using (OleDbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { ExcelRow newRow = new ExcelRow(); for (int count = 0; count &lt; reader.FieldCount; count++) { newRow.AddColumn(reader[count]); } rows.Add(newRow); } } } } catch (Exception ex) { throw ex; } finally { if (conn.State == System.Data.ConnectionState.Open) conn.Close(); } } } public IEnumerator&lt;ExcelRow&gt; GetEnumerator() { Load(); return rows.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { Load(); return rows.GetEnumerator(); } } </code></pre> <p>So, using all this logic, how can I solve my problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload