locked
Find the no of records in a particular SQLite table in windows 8 metro apps RRS feed

  • Question

  • Hi,

    I want to find the no of records in a particular SQLite table.

    Could somebody share the syntax for the same.

    Monday, September 16, 2013 7:49 AM

Answers

  • Hi, Naveen

    Would you want to get the number of records in a particular SQLite table. If so, you can refer to the code below:

    Create simple table by linq to sqlite:

    public class person 
            { 
     
                [MaxLength(5), PrimaryKey] 
                
                public String name { get; set; } 
                [MaxLength(255)] 
                public String address { get; set; } 
                [MaxLength(11)] 
                public Double phone { get; set; } 
            } 
    

    Get the number of records:

    var db = new SQLite.SQLiteConnection(dbPath); 
    var count = (from x in db.Table<person>() select x.name).Count(); 
    

    You can see the link to get more information:

    http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882

    Best Wises!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Friday, September 20, 2013 6:59 AM
    Tuesday, September 17, 2013 6:02 AM

All replies

  • Hello Naveen,

    Try to this:

    SQLiteAsyncConnection conn2 = new SQLiteAsyncConnection(databasepath);
    
    var detail = await conn2.QueryAsync<abc>(select query);
    Debug.WriteLine(detail.count);
    foreach(var a in detail)
    {
    //do what you do with data
    }
    
    //sqlite table structure
    public class abc
    {
    public string a { get; set;}
    public string b { get; set;}
    }

    Monday, September 16, 2013 8:46 AM
  • Hi, Naveen

    Would you want to get the number of records in a particular SQLite table. If so, you can refer to the code below:

    Create simple table by linq to sqlite:

    public class person 
            { 
     
                [MaxLength(5), PrimaryKey] 
                
                public String name { get; set; } 
                [MaxLength(255)] 
                public String address { get; set; } 
                [MaxLength(11)] 
                public Double phone { get; set; } 
            } 
    

    Get the number of records:

    var db = new SQLite.SQLiteConnection(dbPath); 
    var count = (from x in db.Table<person>() select x.name).Count(); 
    

    You can see the link to get more information:

    http://code.msdn.microsoft.com/windowsapps/Sqlite-For-Windows-8-Metro-2ec7a882

    Best Wises!


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Anne Jing Friday, September 20, 2013 6:59 AM
    Tuesday, September 17, 2013 6:02 AM