none
Casting Var to DataTable type RRS feed

  • Question

  • Hello everyone,

    Is there a way to cast a var querry without using foreach loop?

     

     var querry =

    from q in this.database.datatable

    where q.Id1 == XXX    // Id1 is a foreign key

    select q;

    if (querry.Count() > 0)

    {

    foreach (var index in querry)

    {

    refVariable = index.Id2; // Id2 is the primary key

    }

    }


    Can I get index.Id2 without looping?

     

     

    Cheers,

    V

    Friday, September 24, 2010 3:39 AM

Answers

All replies

  • Hello there,

     

    A sample Code is given here

    if(Result.Count() > 0){
        DataTable objtable = Result.CopyToDataTable<DataRow>();
    }

     

    Link is given below

    C# DataTable Foreach Loop
    http://dotnetperls.com/datatable-foreach

    Hope this helps.

     

    Regards,

    Phijo Mathew Philip


    PHIJO MP
    Friday, September 24, 2010 5:12 AM
  • "Can I get index.Id2 without looping?"

    Not sure I understand ththe question and this part makes me think "why?"

    You can specify a list of fields and alias them.

    There are also a number of extension methods available and you can write your own.  The latter would enable you to run code for each of those entries without looping.

    http://www.softlion.com/blogs/post/2009/02/02/Useful-LINQ-extensions.aspx

     

    Friday, September 24, 2010 12:44 PM