locked
Add sqlquery to observablecollection RRS feed

  • Question

  • Hi,

    How do I go about to add my sqlite database-Query to my observablecollection so it triggers an update?

    var GetCat = from cats in db.Table<CatInfo>()
                                      where cats.CatID == forwaded.CatID
                                      select cats;
    
    

    This comes back with the best overloaded method has some invalid arguments

    Cats.Add(GetCat);

    But this works obviously.

    Cats.Add(new Cat { CatName = "Smurf" });
    
    If I change my var to my class it doesn't let me Query it with sqlite.
    Sunday, June 29, 2014 10:16 PM

Answers

  • Your "GetCat" object does not have a type, which is why it's failing. It appears to me that "GetCat" holds a collection of cats, not a single cat. In that case, you need to iterate over the collection and add one at a time:

    var GetCat = from cats in db.Table<CatInfo>()
                                     
    where cats.CatID == forwaded.CatID
                                     
    select cats;
    foreach (cat C in GetCat)
    {
    Cats.Add(C);
    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by coffeebakery Tuesday, July 1, 2014 7:54 PM
    Monday, June 30, 2014 12:38 PM

All replies

  • Your "GetCat" object does not have a type, which is why it's failing. It appears to me that "GetCat" holds a collection of cats, not a single cat. In that case, you need to iterate over the collection and add one at a time:

    var GetCat = from cats in db.Table<CatInfo>()
                                     
    where cats.CatID == forwaded.CatID
                                     
    select cats;
    foreach (cat C in GetCat)
    {
    Cats.Add(C);
    }


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    • Marked as answer by coffeebakery Tuesday, July 1, 2014 7:54 PM
    Monday, June 30, 2014 12:38 PM
  • Works just as you explained it!
    Tuesday, July 1, 2014 7:54 PM