locked
return array from db.execute or db.query

    Question

  • i want to return an array to from winrt(c#) so i have two way either through db.execute or db.query... please suggest me what should i do for returning array:

    public static string getQX(string Squery) { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NRFS.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { var qu = db.Query<NR_FS_FW_TASK_TYPES>(Squery); //return resultset in array } } ---or----- public static string getQXn(string Squery) { var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NRFS.db3"); using (var db = new SQLite.SQLiteConnection(dbpath)) { db.Execute(Squery);

    //return resultset in array

    } }


    please suggest, any new idea also appreciated


    • Edited by nkd108 Monday, March 31, 2014 8:01 AM
    Monday, March 31, 2014 7:44 AM

Answers

  • The following code returns the names of the selected instances as a string array (it requires a using statement for System.Linq on top of your file):

    public static string[] getQX(string Squery)
    {
        var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NRFS.db3");
        using (var db = new SQLite.SQLiteConnection(dbpath))
        {
            var qu = db.Query<NR_FS_FW_TASK_TYPES>(Squery);
            return qu.Select(t => t.NAME).ToArray();
        }
    }

    If that's not what you want, then please explain in more detail how you want the string array containing the result set to look like.

    • Marked as answer by nkd108 Friday, April 04, 2014 11:40 AM
    Tuesday, April 01, 2014 7:58 AM

All replies

  • db.Execute can not return an array, it's not meant to be used for SELECT statements.

    db.Query returns a list, which can be transformed into an array (requires a using statement for System.Collections.Generic on top of your file):

    public static NR_FS_FW_TASK_TYPES[] getQX(string Squery)
            {
                var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NRFS.db3");
                using (var db = new SQLite.SQLiteConnection(dbpath))
                {
                    var qu = db.Query<NR_FS_FW_TASK_TYPES>(Squery);
                    return qu.ToArray();
                }
            }

    Monday, March 31, 2014 9:14 AM
  • it will return generic array i just want to return normal string array, is this possible??

    my class is:

     public class NR_FS_FW_TASK_TYPES
            {
                string TASK_TYPE_ID { get; set; } string NAME { get; set; }
            }

    • Edited by nkd108 Tuesday, April 01, 2014 7:27 AM
    Tuesday, April 01, 2014 6:36 AM
  • The following code returns the names of the selected instances as a string array (it requires a using statement for System.Linq on top of your file):

    public static string[] getQX(string Squery)
    {
        var dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "NRFS.db3");
        using (var db = new SQLite.SQLiteConnection(dbpath))
        {
            var qu = db.Query<NR_FS_FW_TASK_TYPES>(Squery);
            return qu.Select(t => t.NAME).ToArray();
        }
    }

    If that's not what you want, then please explain in more detail how you want the string array containing the result set to look like.

    • Marked as answer by nkd108 Friday, April 04, 2014 11:40 AM
    Tuesday, April 01, 2014 7:58 AM
  • thanks it is working
    Friday, April 04, 2014 11:40 AM