Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy are two nearly identical DataSets behaving different?
    text
    copied!<p>i've got two DataSet with each one DataTable inside.</p> <p>DataSet #1:</p> <pre><code> DataTable table = new DataTable(name); table.Columns.Add("ID", typeof(int)); table.Columns.Add("Customer Name",typeof(string)); table.Columns.Add("Contact Name", typeof(string)); table.Columns.Add("Adress", typeof(string)); table.Columns.Add("City", typeof(string)); table.Columns.Add("Postal Code", typeof(string)); table.Columns.Add("Country", typeof(string)); string mem; Console.Clear(); Console.WriteLine("| {0} | {1} | {2} | {3} | {4} | {5} |", table.Columns[1], table.Columns[2], table.Columns[3], table.Columns[4], table.Columns[5], table.Columns[6]); int count=1; do { table.Rows.Add(count, Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Console.ReadLine(), Convert.ToInt32(Console.ReadLine()), Console.ReadLine()); Console.WriteLine("if finished, type end"); mem=Console.ReadLine(); count++; } while (mem != "end"); DataSet set = new DataSet(); set.Tables.Add(table); </code></pre> <p>and DataSet #2:</p> <p>("load" is DataSet #1)</p> <pre><code> string srch = Console.ReadLine(); string ask = "[Customer Name] like '%"+srch+"%' OR [Contact Name] like '%"+srch+"%' OR [Adress] like '%"+srch+"%' OR [City] like '%"+srch+"%' OR [Postal Code] like '%"+srch+"%' OR [Country] like '%"+srch+"%'"; DataRow[] foundRows = load.Tables[0].Select(ask); DataTable dt = new DataTable(); table.Columns.Add("ID", typeof(int)); table.Columns.Add("Customer Name",typeof(string)); table.Columns.Add("Contact Name", typeof(string)); table.Columns.Add("Adress", typeof(string)); table.Columns.Add("City", typeof(string)); table.Columns.Add("Postal Code", typeof(string)); table.Columns.Add("Country", typeof(string)); foreach (DataRow item in foundRows) { dt.Rows.Add(item.ItemArray); } DataSet set = new DataSet(); set.Tables.Add(dt); </code></pre> <p>When sending DataSet #2 to the function Print(), i get an error at "dtc.AsEnumerable()" with DataSet #1 everything works fine...</p> <pre><code> static void Print(DataSet load) { DataTable dtc = load.Tables[0]; List&lt;int&gt; maxlenght = Enumerable.Range(0, dtc.Columns.Count) .Select(col =&gt; dtc.AsEnumerable() .Select(row =&gt; row[col]).OfType&lt;string&gt;() .Max(val =&gt; val.Length)).ToList(); //rest prints DataTable on a grid in console } </code></pre> <p>How can this be, while both DataSets are identical from structure?</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