How to load dataset using linq to sql queries

Posted on 2011-04-27
Last Modified: 2012-05-11
Dear Experts,

I have one quick quetion that might be very easy for you.

I have the following query that I just convert it to linq.
But having some problem filling the result to dataset.

 var weekending = Convert.ToDateTime(weekend);
            var subquery = (from cs in context.certstatus
                            cs.delete_flag == null &&
                            cs.project_code == project &&
                            cs.ctr_license == ctr_license &&
                            cs.week_ending_on == weekending
            var sSelQuery = (from j in context.journals
                            j.delete_flag == null &&
                            j.jrnl_sub_type == "cprnote" &&
                            j.jrnl_type == "adminnotes" &&
                            subquery.Contains (j.jrnl_lineid)
                         select new

                            }).OrderBy(r => r.date_created);

I used some thing like this:

 DataSet ds = new DataSet("SelQuery");

but it is not compiling. How can I fill this result in to data set?
Question by:kate2001
    LVL 21

    Expert Comment

    LVL 21

    Expert Comment


    Author Comment

    Thanks Alfred1,

    Now I just get it in to my dataset.
    using  ToDataSet extension method.

    DataSet ds = selQuery.ToDataSet("Journals")

    I wanted to know the number of rows in the dataset but i have no clue...

    Thank you inadvance
    LVL 21

    Accepted Solution

    You need to count the number of rows in a datatable within a dataset.  For example, using your dataset, assuming your datatable is named "Journals", you can do the following:

    DataSet ds = selQuery.ToDataSet("Journals");
    int RowCount = ds.Tables["Journals"].Rows.Count;

    Or, if you have only one table in your dataset, you could just do it this way:

    DataSet ds = selQuery.ToDataSet("Journals");
    int RowCount = ds.Tables[0].Rows.Count;


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Creating and Managing Databases with phpMyAdmin in cPanel.
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now