0
votes

I'm new to windows app development.How can I make sqlite database in windows phone 8 app?This link shows how to use local databse but I want sqlite databse http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202876(v=vs.105).aspx

thanks in advance....

1
do you have a existing database or u want to create in app ? - Sandeep Chauhan
I am creating a database in windows phone app using linq2sql and I want my database to be updated from the server as my app is downloaded on mobilephone. I am using Linq2sql,is it better than sqlite (I want my app to run on wp7,7.5,8)? - Dr.John

1 Answers

0
votes

you can download a nuget package called sqlite for windows phone. then you can a .db file in your project or can create a new by using following code.

  public static SQLiteAsyncConnection connection;
  public static bool isDatabaseExisting;

  public static async void ConnectToDB()
        {
            try
            {
                StorageFile storageFile = await ApplicationData.Current.LocalFolder.GetFileAsync("DelhiMetroDB.db");
                isDatabaseExisting = true;
            }
            catch (Exception ex)
            {
                isDatabaseExisting = false;
            }

            if (!isDatabaseExisting)
            {
                try
                {
                    StorageFile databaseFile = await Package.Current.InstalledLocation.GetFileAsync("DelhiMetroDB.db");
                    await databaseFile.CopyAsync(ApplicationData.Current.LocalFolder);
                    isDatabaseExisting = true;
                }
                catch (Exception ex)
                {
                    isDatabaseExisting = false;
                }
            }

            if (isDatabaseExisting)
            {                   
                connection = new SQLiteAsyncConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "DelhiMetroDB.db"), true);
            }
        }
    }
}

then you can use this variable connection to connect with database like :

 var result= classname.connection.QueryAsync<objecttype>("SELECT * FROM tablename").Result;