2014-02-05 55 views
0

我新的Windows应用程序development.How我可以让SQLite数据库中的Windows Phone 8应用?此链接说明了如何使用本地DATABSE但我想sqlite的DATABSE http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202876(v=vs.105).aspxSQLite数据库8应用

感谢提前...

+0

你有一个现有的数据库或u想在应用创建? –

+0

我正在使用linq2sql在windows phone应用程序中创建数据库,并且我希望从服务器更新数据库,因为我的应用程序是在手机上下载的。我使用Linq2sql,是否比sqlite好(我希望我的应用程序在wp7,7.5,8上运行)? –

回答

0

你可以下载一个叫做sqlite的nuget包,用于windows phone。 然后你可以在你的项目中使用.db文件,或者使用下面的代码创建一个新文件。

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); 
      } 
     } 
    } 
} 

,那么你可以使用这个变量连接到与像数据库连接:

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