【发布时间】:2017-10-30 02:52:37
【问题描述】:
有没有人知道如何解决这个错误信息
错误 CS1729:“SQLiteConnection”不包含采用 1 个参数的构造函数 (CS1729)
这是发生的文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using SQLite;
using Android.Util;
using SQLite.Net;
namespace CPDEP1
{
public class DataBase
{
string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
public bool createDataBase()
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")));
{
connection.CreateTable<Person>();
return true;
}
}
catch(SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public bool insertIntoTablePerson(Person person)
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
connection.Insert(person);
return true;
}
}
catch(SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public List<Person> selectTablePerson()
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
return connection.Table<Person>().ToList();
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return null;
}
}
public bool updateTablePerson(Person person)
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
connection.Query<Person>("UPDATE Person set Nom=?,Prenom=?,Telephone=?,Addresse=?,Courriel=?,Cin=? Where Id=?,",person.Nom,person.Prennom,person.Telephone,person.Addresse,person.Courriel,person.Cin,person.Id);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public bool deleteTablePerson(Person person)
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
connection.Delete(person);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
public bool selectQueryTablePerson(int Id)
{
try
{
using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db")))
{
connection.Query<Person>("SELECT * FROM Person Where Id=?", Id);
return true;
}
}
catch (SQLiteException ex)
{
Log.Info("SQLiteEx", ex.Message);
return false;
}
}
}
}
提前感谢您的帮助
【问题讨论】:
-
其实我用的是Xamarin Studio,我只有一个项目和解决方案
-
我认为你的数据库连接字符串应该以
"DataSource="开头 -
你确定你有正确的库吗,这个github.com/praeclarum/sqlite-net 有一个构造函数
SQLiteConnection,就像你的代码一样,并且有命名空间using namespace SQLite,而using namespace SQLite.Net看起来像这个库github.com/oysteinkrog/SQLite.Net-PCL,并且需要SQLiteConnection(平台实例)的附加参数。 -
您是对的,先生!我使用了错误的库,我卸载了我正在使用的库并将其替换为正确的库,一切正常。谢谢
标签: c# android sqlite xamarin.android