?
Solved

How to load dataset using linq to sql queries

Posted on 2011-04-27
4
Medium Priority
?
454 Views
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
                           where
                            cs.delete_flag == null &&
                            cs.project_code == project &&
                            cs.ctr_license == ctr_license &&
                            cs.week_ending_on == weekending
                         select
                           cs.record_id).ToList();
            var sSelQuery = (from j in context.journals
                        where
                            j.delete_flag == null &&
                            j.jrnl_sub_type == "cprnote" &&
                            j.jrnl_type == "adminnotes" &&
                            subquery.Contains (j.jrnl_lineid)
                         select new
                            {
                                j.jrnl_text,
                                j.date_created,
                                j.jrnl_lineid

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


I used some thing like this:

 DataSet ds = new DataSet("SelQuery");
            ds.Tables.Add(SelQuery.CreateDataTable("journals");

but it is not compiling. How can I fill this result in to data set?
0
Comment
Question by:kate2001
  • 3
4 Comments
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35482730
0
 
LVL 21

Expert Comment

by:Alfred A.
ID: 35482786
0
 

Author Comment

by:kate2001
ID: 35486905
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
0
 
LVL 21

Accepted Solution

by:
Alfred A. earned 2000 total points
ID: 35490384
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;

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

840 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