c# - Wrong path to SQLiteDB (or copy) on WinPhone. Xamarin.Forms PCL -


have installed nuget packages xamarin.forms pcl. have 4 projects droid, ios, win 8.1 , winphone 8.1. tried connect database, encountered trouble: win , winphone projects don`t see or return me wrong path. followed official xamarin.forms forum.

interface:

public interface isqlite {     string getdatabasepath(string filename); } 

winphone class:

using system.io; using windows.storage; using baumizer.winphone; using xamarin.forms;  [assembly: dependency(typeof(sqlite_winphone))] namespace baumizer.winphone {     public class sqlite_winphone:isqlite {     public sqlite_winphone() { }     public string getdatabasepath(string filename)     {         return path.combine(applicationdata.current.localfolder.path, filename);     } }} 

this class selecting info:

public class database {     sqliteconnection connection;      public database()     {         connection= new sqliteconnection(dependencyservice.get<isqlite>().getdatabasepath("database.db"));     }      public ienumerable<group> getgroups()     {         return connection.query<group>("select * [scedule] [facultyname] =" + "'" + data.currentfaculty + "'");     } } 

it works on android. on winphone exception of sqlite - no such table: scedule. open local directory emulator db - 0kb. put db assets , set buildinaction content. what`s wrong? need help

on forum find code, putted onlaunched(...) in winphone app.cs:

if(await applicationdata.current.localfolder.getitemasync(data.databasename) == null)         {             storagefile databasefile = await package.current.installedlocation.getfileasync($"assets\\{data.databasename}");             await databasefile.copyasync(applicationdata.current.localfolder);         } 

it copies db if it's not exist, is. may need delete db 0kb, don't know how this.

it's work, onlaunched():

try         {             await applicationdata.current.localfolder.getitemasync("scedule.db");         }         catch (system.io.filenotfoundexception)         {             storagefile databasefile =                     await package.current.installedlocation.getfileasync($"assets\\{"scedule.db"}");             await databasefile.copyasync(applicationdata.current.localfolder);         } 

db uncorrectly copied. may there ways.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -