【问题标题】:: Error CS1729: 'SQLiteConnection' does not contain a constructor that takes 1 arguments (CS1729):错误 CS1729:“SQLiteConnection”不包含采用 1 个参数的构造函数 (CS1729)
【发布时间】: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


【解决方案1】:

我按照这里的说明进行操作:https://wolfprogrammer.com/2016/09/10/adding-a-sqlite-database-to-xamarin-forms/ 并得到了同样的错误。

然后我在这里参考了 Microsoft 指令 (https://msdn.microsoft.com/en-us/magazine/mt736454.aspx) 并注意到有 2 个非常相似的东西都是由 Frank Krueger 编写的。请检查下面的图片,下载以绿色突出显示的那张,而不是红色的那张。

【讨论】:

  • 绿色和红色方块帮助我在不到一秒的时间内发现我的错误!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-13
  • 1970-01-01
相关资源
最近更新 更多