locked
show data in texbox sqlite c# RRS feed

  • Question

  • hello, 

    I use a texbox to display a given of my table, and the query just want FristName but also repay me your ID.

    the code:

    outputbox.Text += db.Query<Person>("Select FristName From Person where ID=1 ").Single();

    and my table is this:

     public class Person
            {
                [AutoIncrement, PrimaryKey]
                public int ID { get; set; }

                public string FristName { get; set; }
                public string LastName { get; set; }


                public override string ToString()
                {
                    return string.Format("{0} {1} {2}", ID, FristName, LastName);
                }
            }

    thanks


    Thursday, October 3, 2013 11:01 AM

Answers

  • Hi.

    Change your query like this:

    var person = db.Query<Person>("Select FristName From Person where ID=1 ").Single();
    outputbox.Text += person.FristName ;

    Also, I recommend you to not use Single() method, Because you'll get exception if this query didnt find any item in table. You can use FirstOrDefault() instead Single() and check returned object for null.

    PS: rename FristName to FirstName :)

    Thursday, October 3, 2013 1:07 PM

All replies

  • Hi.

    Change your query like this:

    var person = db.Query<Person>("Select FristName From Person where ID=1 ").Single();
    outputbox.Text += person.FristName ;

    Also, I recommend you to not use Single() method, Because you'll get exception if this query didnt find any item in table. You can use FirstOrDefault() instead Single() and check returned object for null.

    PS: rename FristName to FirstName :)

    Thursday, October 3, 2013 1:07 PM
  • thanks it's work 
    Thursday, October 3, 2013 1:26 PM