Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem here is that <code>res1</code> is a collection of <code>DataRow</code> and its non indexed <a href="http://msdn.microsoft.com/en-us/library/system.data.datarow.aspx" rel="nofollow">properties</a> are being rendered as columns. </p> <h1>Solution 1</h1> <p>You can select an <a href="http://msdn.microsoft.com/en-us/library/bb397696.aspx" rel="nofollow">anonymous type</a> of object with the row's contents as its properties.</p> <p>e.g.,</p> <pre><code>var tbl1 = tb1; var tbl2 = tb2; var res1 = from t2 in tbl2.AsEnumerable() join t1 in tbl1.AsEnumerable() on t2["BBL"] equals t1["BBL"] into g from t1 in g.DefaultIfEmpty() where t1 == null select new { Amount = t2["amount"], Payee = t2["payee"] }; </code></pre> <p>where <code>amount</code> and <code>payee</code> are two columns in <code>tb2</code>.</p> <p>If you set <code>AutoGenerateColumns</code> on <code>dataGridView3</code> to <code>true</code>, then the names of the properties of this anonymous class (viz. <code>Amount</code> and <code>Payee</code>) will be used as column names.</p> <h1>Solution 2</h1> <p>As in your comment you said that you wanted to show all columns, so here is another less elegant solution (please leave your Linq expression as is):</p> <pre><code>foreach (DataColumn dCol in tbl1.Columns) { dataGridView1.Columns.Add(dCol.ColumnName, dCol.Caption); } foreach (var s in res1) { foreach (var item in res1) { dataGridView1.Rows.Add(item.ItemArray); } } </code></pre> <p>You should remove the <code>dataGridView3.DataSource = res1;</code> if you go ahead with this approach.</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