Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我在做什么,有什么问题。但是为了您的理解,我正在编辑这个问题。当抛出异常时,异常会说哪个对象为null?当它执行代码数据库时。Query(stringquery);我感谢你的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用_Ios_Database_Sqlite_Xamarin.ios_Xamarin.forms - Fatal编程技术网

Ios 我在做什么,有什么问题。但是为了您的理解,我正在编辑这个问题。当抛出异常时,异常会说哪个对象为null?当它执行代码数据库时。Query(stringquery);我感谢你的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用

Ios 我在做什么,有什么问题。但是为了您的理解,我正在编辑这个问题。当抛出异常时,异常会说哪个对象为null?当它执行代码数据库时。Query(stringquery);我感谢你的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用,ios,database,sqlite,xamarin.ios,xamarin.forms,Ios,Database,Sqlite,Xamarin.ios,Xamarin.forms,我在做什么,有什么问题。但是为了您的理解,我正在编辑这个问题。当抛出异常时,异常会说哪个对象为null?当它执行代码数据库时。Query(stringquery);我感谢你的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用“sqlite net pcl”,还是使用“microsoft.entityframeworkcore.sqlite”nuget包?我问的原因是1)我正在尝试使用Microsoft one,2)没有任何示例显示它使用了“连接”对象,并且在自动完


我在做什么,有什么问题。但是为了您的理解,我正在编辑这个问题。当抛出异常时,异常会说哪个对象为null?当它执行代码数据库时。Query(stringquery);我感谢你的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用“sqlite net pcl”,还是使用“microsoft.entityframeworkcore.sqlite”nuget包?我问的原因是1)我正在尝试使用Microsoft one,2)没有任何示例显示它使用了“连接”对象,并且在自动完成点表示法中没有“表”,如您在此处所示。您好@Donna!这使用了sqlite net pcl:非常感谢您的评论。这看起来像是我在别处见过的,所以让我问一下。。。您提供的这种代码/方法是使用“sqlite net pcl”,还是使用“microsoft.entityframeworkcore.sqlite”nuget包?我问的原因是1)我正在尝试使用Microsoft one,2)没有任何示例显示它使用了“连接”对象,并且在自动完成点表示法中没有“表”,如您在此处所示。您好@Donna!这使用sqlite net pcl:
using SQLite;

namespace SampleApp
{
    public interface ISQLite
    {
        SQLiteAsyncConnection GetConnection();
    }
}
using System.IO;

using SampleApp.Droid;

using SQLite;

using Xamarin.Forms;

[assembly: Dependency(typeof(SQLite_Android))]
namespace SampleApp.Droid
{
    public class SQLite_Android : ISQLite
    {
        #region ISQLite implementation
        public SQLiteAsyncConnection GetConnection()
        {
            var sqliteFilename = "DatabaseFileName.db3";
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);

            var conn = new SQLiteAsyncConnection(path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache);

            // Return the database connection 
            return conn;
        }
        #endregion
    }
}
using System;
using System.IO;

using SQLite;

using Xamarin.Forms;

using SampleApp.iOS;

[assembly: Dependency(typeof(SQLite_iOS))]
namespace SampleApp.iOS
{
    public class SQLite_iOS : ISQLite
    {
        #region ISQLite implementation
        public SQLiteAsyncConnection GetConnection()
        {
            var sqliteFilename = "DatabaseFileName.db3";
            string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
            string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder
            var path = Path.Combine(libraryPath, sqliteFilename);

            var conn = new SQLiteAsyncConnection(path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.SharedCache);

            // Return the database connection 
            return conn;
        }
        #endregion
    }
}
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;

using SQLite;

using Xamarin.Forms;

namespace SampleApp
{
    public static class SampleModelDatabase
    {
        #region Constant Fields
        static readonly SQLiteAsyncConnection _database = DependencyService.Get<ISQLite>().GetConnection();
        #endregion

        #region Fields
        static bool _isInitialized;
        #endregion

        #region Methods

        public static async Task<IList<SampleModel>> GetAllItemsAsync()
        {
            if (!_isInitialized)
                await Initialize();

            return await _database.Table<SampleModel>().ToListAsync();
        }

        public static async Task<int> SaveItemAsync(SampleModel model)
        {
            if (!_isInitialized)
                await Initialize();

            return await _database.InsertOrReplaceAsync(model);
        }

        public static async Task<int> DeleteItemAsync(SampleModel model)
        {
            if (!_isInitialized)
                await Initialize();

            return await _database.DeleteAsync(model);
        }

        public static async Task<int> GetNumberOfRowsAsync()
        {
            if (!_isInitialized)
                await Initialize();

            return await _database.Table<SampleModel>().CountAsync();
        }

        static async Task Initialize()
        {
            await _database.CreateTableAsync<SampleModel>();
            _isInitialized = true;
        }
        #endregion
    }
}
await Connectdb();
// now do your query
var treatment = _database.Query<ClassName>("SELECT * FROM [TableName] WHERE ...");
DependencyService.Get<IDatabaseConnection>().DbConnection();