Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Do computers have mood ?

c# linq to sql sql server

Best Answer lespauled, 08 April 2014 - 08:55 AM

Put a breakpoint at your switch statement and see if if orc ever equals the other criteria.   Also you might want to compare the date values differently.  Your way, the format of the parameter must be exactly the same, or there will be 0 results.

 

Your best bet is the step through the debugger, and check out all values.  First to see if the options part of the switch works correctly, and secondly to tell you if your search criteria is working correctly.  

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1 phi

phi

    CC Regular

  • Member
  • PipPipPip
  • 33 posts

Posted 08 April 2014 - 08:23 AM

I am developing a web application with webforms. I use linq to sql to query the database (sql server). Here is a method I use to search for specific rows based on criteria such as e-mail, name and date.

internal List<Agent> searchComptesAgent(string s, OptionRechercheComptes orc)
        {
            LAgt = null;
            try
            {
                using (TDC = new TequilaDataContext())
                {
                    switch (orc)
                    {
                        case OptionRechercheComptes.Date:
                            LAgt = (from agt in TDC.Agents
                                    where agt.DateHeureCreation.ToString("dd-MM-yyyy").Equals(s)
                                    select agt).ToList<Agent>();
                            break;
                        case OptionRechercheComptes.Email:
                            LAgt = (from agt in TDC.Agents
                                    where agt.EmailAgent.Equals(s)
                                    select agt).ToList<Agent>();
                            break;
                        case OptionRechercheComptes.Nom:
                            LAgt = (from agt in TDC.Agents
                                  where agt.Nom.Contains("Diallo") || agt.Prenoms.Contains("Irene")
                                  select agt).ToList<Agent>();
                            break;
                    }
                }
            }
            catch (Exception E) { }
            return LAgt;
        }

It works only when I query for rows base on an e-mail. I have tried to run it in a different application, it works fine ! Sometimes I tend to think that computers have moods !  :confused:


Love what you do and you will be successful...


#2 lespauled

lespauled

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1360 posts

Posted 08 April 2014 - 08:55 AM   Best Answer

Put a breakpoint at your switch statement and see if if orc ever equals the other criteria.   Also you might want to compare the date values differently.  Your way, the format of the parameter must be exactly the same, or there will be 0 results.

 

Your best bet is the step through the debugger, and check out all values.  First to see if the options part of the switch works correctly, and secondly to tell you if your search criteria is working correctly.  


My Blog: http://forum.codecal...699-blog-77241/
"Women and Music: I'm always amazed by other people's choices." - David Lee Roth

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 08 April 2014 - 08:56 AM

Nope, just subtle, twitchy issues :)


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 phi

phi

    CC Regular

  • Member
  • PipPipPip
  • 33 posts

Posted 08 April 2014 - 10:55 AM

Put a breakpoint at your switch statement and see if if orc ever equals the other criteria.   Also you might want to compare the date values differently.  Your way, the format of the parameter must be exactly the same, or there will be 0 results.

 

Your best bet is the step through the debugger, and check out all values.  First to see if the options part of the switch works correctly, and secondly to tell you if your search criteria is working correctly.  

 

I have done what you said and I think the problem is the data type of the variable I use get the rows from the linq query (LAgt). I was using something like :

List<Table_Name> LAgt

I have tried var and it works fine. The thing is I want to do any query in a specific class and not in the code behind the asp page so passing parameters is key. 


Love what you do and you will be successful...





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download