locked
Inserting data in SQL lite databse

    Question

  • Dear all,

    I have a data model class which contains set of object representing data that I should be able to manipulate from a database.
    That data model class is already used with our Windows application and SQL server express database.

    I need to build a WinRt version of our app and for that my idea was to use SQLlite as the storage.
    For that I have created the SQLite databse file from my SQL Server express version using free tool

    From my Windows app I have build a Sync process using LINQ which connect to a Web service and insert data in SQL server Express.

    My goal now is to be able to use that same Library which connect to web service, but instead of having the destination as SQL server it will be SQLLITE db file.

    The problem I have seen in different exemple of SQL lite is that they use Code First approach and for that the classes Name have same name as Table name.

    IN my scenario my Library has different class naming that the table colomn.

    Does that means that I will need to rename all my classes or is there a way to use my Library as it is and simply the databse connection is different ?

    thanks for advise

    regards

    Saturday, April 04, 2015 1:31 PM

Answers

  • Hello, thnaks for your reply.

    I could not find the properway to open a database SQlite and access data using sql querry.

    All exemple use either a connection string to be define and some others use for instance as bellow :

    using (var db = new SQLite.SQLiteConnection(dbPath))
                {
    ...
    }

    I decide to go with code above but then how can I execute a simple querry as below :

     using (var db = new SQLite.SQLiteConnection(dbPath))
                {
                    string sql = "select * from AddressType";
                    SQLiteCommand cmd = new SQLiteCommand(db);
                    cmd.CommandText = sql;
                    
    ... ?????
    
                }

    How can I retrive the list of records ?

    Sorry gets confused

    regards


    Hi wakefun,

    If you wat to perform raw SQLite query with multiple row result through SQLiteAsyncConnection, the official way is using Linq, or you need to extend the original class, check this thread: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/f8e2466c-6cdc-4e45-a935-1c5b2dd524bd/how-to-perform-raw-sqlite-query-with-multiple-row-result-through-sqliteasyncconnection?forum=winappswithcsharp


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by wakefun Thursday, April 09, 2015 2:07 PM
    Thursday, April 09, 2015 1:07 PM
    Moderator

All replies

  • Hi wakefun,

    >>Does that means that I will need to rename all my classes or is there a way to use my Library as it is and simply the databse connection is different ?

    No, you can make this work by executing query statement directly instead of using Linq, see this thread and check my reply: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/4f783f06-936e-4900-beb7-f638e25669f0/error-sqlite?forum=wpdevelop


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 06, 2015 7:07 AM
    Moderator
  • You may refer to this URL

    http://blogs.windows.com/buildingapps/2013/03/12/using-the-sqlite-database-engine-with-windows-phone-8-apps/

    Tuesday, April 07, 2015 1:00 AM
  • Hello, thnaks for your reply.

    I could not find the properway to open a database SQlite and access data using sql querry.

    All exemple use either a connection string to be define and some others use for instance as bellow :

    using (var db = new SQLite.SQLiteConnection(dbPath))
                {
    ...
    }

    I decide to go with code above but then how can I execute a simple querry as below :

     using (var db = new SQLite.SQLiteConnection(dbPath))
                {
                    string sql = "select * from AddressType";
                    SQLiteCommand cmd = new SQLiteCommand(db);
                    cmd.CommandText = sql;
                    
    ... ?????
    
                }

    How can I retrive the list of records ?

    Sorry gets confused

    regards

    Tuesday, April 07, 2015 8:28 AM
  • Hello, thnaks for your reply.

    I could not find the properway to open a database SQlite and access data using sql querry.

    All exemple use either a connection string to be define and some others use for instance as bellow :

    using (var db = new SQLite.SQLiteConnection(dbPath))
                {
    ...
    }

    I decide to go with code above but then how can I execute a simple querry as below :

     using (var db = new SQLite.SQLiteConnection(dbPath))
                {
                    string sql = "select * from AddressType";
                    SQLiteCommand cmd = new SQLiteCommand(db);
                    cmd.CommandText = sql;
                    
    ... ?????
    
                }

    How can I retrive the list of records ?

    Sorry gets confused

    regards


    Hi wakefun,

    If you wat to perform raw SQLite query with multiple row result through SQLiteAsyncConnection, the official way is using Linq, or you need to extend the original class, check this thread: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/f8e2466c-6cdc-4e45-a935-1c5b2dd524bd/how-to-perform-raw-sqlite-query-with-multiple-row-result-through-sqliteasyncconnection?forum=winappswithcsharp


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by wakefun Thursday, April 09, 2015 2:07 PM
    Thursday, April 09, 2015 1:07 PM
    Moderator