none
count in c# using linq with gridview in asp.net RRS feed

  • Question

  • So I am working on this that grabs data and counts it.

    So I have 7 scales and I have ti so those 7 shows up in diffrent rows. What I want is to count each row seprate. And each row as 7 colums. So this is what I have.

    var ** = (from m in MAN.***.AsEnumerable()
                                  where m.Date_Processed != null &&
                                  m.Date_Processed.Value >= Start &&
                                  m.Date_Processed.Value <= End
                                  orderby m.Date_Processed descending
                                  select m.**.ToList().Distinct();
                    
                    var *** = (from m in MAN.***.AsEnumerable()
                                  where m.Date_Processed != null
                                  && m.Main_Port == 1 && 
                                  m.Date_Processed.Value >= Start &&
                                  m.Date_Processed.Value <= End
                                  orderby m.Date_Processed descending
                                  select m).ToList().Count();

    So the 1st one is getting the scales. That works fine. 2nd part I do not understand. I know WHY it is counting everything and filling in all the scales with same number but I would like to know how to count only on that 1 scale skip go to next scale count and so forth.

    Thanks for any help.


    Monday, July 8, 2013 1:51 PM

All replies

  • Not completely clear about your requirement, however want to mention that you have to take common part of your query and bring results from SQL to application.

    (from m in MAN.***.AsEnumerable()
                                  where m.Date_Processed != null &&
                                  m.Date_Processed.Value >= Start &&
                                  m.Date_Processed.Value <= End
                                  orderby m.Date_Processed descending
                                  select m).ToList()

    Than continue work with your sequence, this will rise your performance up. You don't have to send the same query to your database.


    Please Mark as Answer and Vote as Helpful if I helped.

    Also please visit my blog http://www.msguy.me/


    Monday, July 8, 2013 7:06 PM

  • The reason I have

    && m.Main_Port == 1

    is so I can search for the 1 thing. And what I mean is.

    That 1st part makes it so in my gridview

    var a = (from m in MAN.***.AsEnumerable()
                                  where m.Date_Processed != null &&
                                  m.Date_Processed.Value >= Start &&
                                  m.Date_Processed.Value <= End
                                  orderby m.Date_Processed descending
                                  select m.**.ToList().Distinct();

     a = a.OrderBy(z => z.Value);
                    if (**.First().Value == 1)
                    {
                        foreach (int i in a)
                        {
                            dt.Rows.Add(new object[] { i, **, });
                            
                        }
                    }

    That makes it so foreach a make a new row which is a scale which is only 7. Each row has 7 lanes

    var *** = (from m in MAN.***.AsEnumerable()
                                  where m.Date_Processed != null
                                  && m.Main_Port == 1 && 
                                  m.Date_Processed.Value >= Start &&
                                  m.Date_Processed.Value <= End
                                  orderby m.Date_Processed descending
                                  select m).ToList().Count();

    I want it so when it goes to that lane look at all the scales in that lane and then count all that is on scale 1 lane 1 then count scale 2 lane 1 and so forth. But right now it is counting everything that is in lane 1 and putting it in every row.

    Sorry if this does not make any sense. Tried to my best to explain.

    Monday, July 8, 2013 8:01 PM