Site Search:
Sign in | Join | Help

This Blog

Syndication

Tags

ComponentArt

September 2008 - Posts

  • Populating a ComponentArt grid using linq

    Here is a thread that I had with Component Art support. I have not tested this - I have largely dropped my testing of Linq to sql because of this issue. I have problems with Janus Winform grids also.

    Sirs:

    I'm trying to start using linq in a web form.

     

    I can't get a grid to bind to a resultset that comes from a stored procedure.

    The error that I'm getting is 'Object reference not set to an instance of an object' when databinding.

     

    I see a post that mentions converting the ISINGLERESULT into a Datatable, but can't figure that out.

     

    Can you help?

     

    Hello,

     

    That error isn't what I'd expect to see- are you able to bind this linq query to a standard datagrid?

     

    The error we're aware of is that the grid can't enumerate through a linq data source; thus, something like this:

     

    Grid1.DataSource = from person in people select person; Grid1.DataBind(); 

     

    Fails with a nullreferenceexception. To workaround that, you could do

    this:

     

    var linq = from person in people select person; Grid1.DataSource = linq.ToList(); Grid1.DataBind();

     

    So in your code, set your results to a var type, then cast the type to one the grid can enumerate (a list as above, or a DataTable, etc).

     

    Stephen Hatcher

    Developer Support Manager

    ComponentArt Inc.

     

     

    Sirs:

    Your examples are using standard linq to sql access, I'm using the *stored

    procedure* access.

    Scott Gu demonstrates this here

    http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-ret

    riev

    ing-data-using-stored-procedures.aspx

     

    All my data access is via stored procs.

     

    I'd be happy with the '.tolist' approach, but I can't get a stored procedure result to do that. Can you help?

     

     

     

    Hello,

     

    I see. Unless I'm mistaken (and I very well could be), this article shows you how to do that. Unfortunately it's all images, but take a look at this one:

     

    http://www.scottgu.com/blogposts/linqsproc1/step12.jpg

     

    You can see him casting his proc to a list there. In a previous example, you can see him set the results of his proc to the var type as well:

     

    http://www.scottgu.com/blogposts/linqsproc1/step6.jpg

     

    So you could use that, then use ToList on the var. Does that make sense?

      

    Stephen Hatcher

    Developer Support Manager

    ComponentArt Inc.