1

I am using SQLite database for my Windows Store app. I completed my requirement of usage of Database with the help of MSFT samples & Blogs. Now I want to Change/Update the Data which is in the Database File..

My Insert code like this..

                   using (var db = new SQLite.SQLiteConnection(dbpath))
                    {
                        db.Insert(new ItemEpub.EpubBookList()
                        {
                            BookName = file.DisplayName,
                            BookPath = file.Path,
                        }
                        );
                        db.Commit();
                        db.Dispose();
                        db.Close();
                    }

I didn't get the Syntax & any simple information about Update the Database table. Right now my code is:

    StorageFile DataFile = await ApplicationData.Current.LocalFolder.GetFileAsync("Epub.db3");
        using (var db = new SQLite.SQLiteConnection(dbpath))
        {
            db.Update EpubBookList Set
            string sql = UPDATE EpubBookList SET LastVisitedPage = '" + lastVisistedPageIndex + "',";
            db.Dispose();
            db.Close();
        }

May be this code looks like ugly, Apart from this code give me any Suggestion on Update the Exiting row in metro apps

1 Answer 1

1

To update the existing record, first you need to get that object via SQL query [Query<T>(...)] or Get<T>(...) method. Then update the object properties and call Update(...) method.

using (var db = new SQLite.SQLiteConnection(dbpath))
{
        var objPerson = db.Query<Person>("select * from dbPerson where PersonId = ?", 9);

        /*** or ***/

        var objPerson = db.Get<Person>(9); // Here 9 is primary key value

        /*** update the object ***/

        objPerson.FirstName = "Matt";
        db.Update(objPerson);
}

You don't need to call db.Dispose(); & db.Close(); because you are using using.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks you. It determines clearly for me. Can you post the relevant web link of blog or page which describes Advanced SQLite concepts. which are more about CURD operations & using Keys in database, I am some what new to DB. I already go through Some samples of MSFT.
There's no sample I think in my mind. Better you post here if you are facing any issue.
Nope, no need of sample,.. & Right now I don't have any issues with what I did. I want to know any Blog that you know about Advanced Sqlite. even I didn't get syntaxs for Update, delete & select commends with conditions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.