none
Can i Bind 2 query results to to be one result set RRS feed

  • Question

  • Hi

    if i have 2 query results res1 and res2 and res1 outputs 3 columns and res2 outputs 2 columns and both results from the same table i want to show all five columns in one grid can i do this?


    nothing beat the human brain
    Monday, May 17, 2010 12:42 PM

All replies

  • Maybe something like this?

        var res1 =
    	from c in Table
    	select new
    	{
    		c1 = c.Column1,
    		c2id = (int?)c.Column2ID,
    		c3id = (int?)c.Column3ID,
    		c4id = (int?)null
    	};
    	
    	var res2 =
    	from c in Table
    	select new
    	{
    		c1 = null,
    		c2id = (int?)null,
    		c3id = (int?)c.Column3ID,
    		c4id = (int?)c.Column4ID
    	};
    	
    	var result =
    	r1.Union( r2 );

     

    Monday, May 17, 2010 7:51 PM
  • thanks for reply

    i don't mean union the results i mean union columns

    like this

    c1id-c2id-c3id-c4id-c5id

     


    nothing beat the human brain
    Tuesday, May 18, 2010 3:20 AM
  • Hi seco,

    Does these two query results have common properties or columns ? Could you please post the code for these two queries ? Thank you.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, May 19, 2010 3:38 AM
    Moderator
  • Well, not sure if will work for you or even if is a good idea but any query return a IEnumerable and every element of it is a record of the table who match the condicion.  You could use Zip<> to merge the two query results into one using  a predicate function that format each element.

    You have to be a bit more specific if you want code.

    Sorry if it was not helpfull.

    Wednesday, May 19, 2010 3:47 PM