0

Hi so i'm using linq to sql through table mapping. Which works. But as I'm new to C# as well as WPF I seem to be incapable of finding a way to populate a datagrid with IQueryable. My Query looks like this.

var STL = new STDB.reportDB(Properties.Settings.Default.dataConnString);
DateTime startDate = new DateTime(2015,2,1);

IQueryable<STDB.salesInvLine> lastMonthInvoiced = from salesinv in STL.Sales_Inv_Lines
                                                          where (salesinv.Shipment_Date.Year == startDate.Year
                                                              && salesinv.Shipment_Date.Month == startDate.Month)
                                                          select salesinv;

dataGrid01.ItemsSource = lastMonthInvoiced;

This gives me a NullReferenceException error. Which as i understand it doesn't help very much as far as errors go.

I've also tried switching IQueryable with datagrid01.ItemsSource but no dice. I've bumped into examples that utilise the using().to list(); but i cant seem to tailor those methods to my own tables probably because i don't fully understand them. I am able to access individual rows with

foreach (STDB.salesInvLine salesinv in lastMonthInvoiced)
{
      string code = salesinv.Document_No_;
      DateTime ddate = salesinv.Shipment_Date;                
}

But even still I can't figure out how to get this into a Datagrid. If someone could point me in the right direction please that would be much appreciated. I don't wanna have to give up and go back to VB.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
WouldBeNerd
  • 629
  • 11
  • 29
  • "This gives me a NullReferenceException error. Which as i understand it doesn't help very much as far as errors go." Ugh, no. Wrong. The error tells you everything you need to know about what happened and you can use that info to fix your problem. Here's the guide for debugging dupes. If you do this and are still stuck, [edit] your question and include the information you gathered while debugging the NRE. Then @me in a comment and I can reopen. Also, research MVVM. And, lastly, IQ as a DataSource is not the best. ToArray() it first. –  May 13 '15 at 12:35
  • Thanks Soner! I'll do my best :) – WouldBeNerd May 13 '15 at 12:42

0 Answers0