原文链接

https://www.cnblogs.com/zhaoliankun/p/9088200.html

我的环境配置:windows 64,VS,SQLite(点击下载),System.Data.SQLite.DLL(点击下载)。

1.在VS中新建一个控制台应用程序,如下图

2.添加引用

将下载的System.Data.SQLite.DLL复制到新建项目的路径下

在VS中找到项目,右键选择添加引用

浏览到dll路径下,添加进来。

代码中添加

using System.Data.SQLite;

添加类库CSQLiteHelper,用于存放SQLite操作方法(此代码原文链接. https://blog.csdn.net/pukuimin1226/article/details/8516733

具体代码

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Data;
using System.Xml;
using System.Text.RegularExpressions;
using System.IO; namespace CSharp_SQLite
{
public class CSQLiteHelper
{
private string _dbName = "";
private SQLiteConnection _SQLiteConn = null; //连接对象
private SQLiteTransaction _SQLiteTrans = null; //事务对象
private bool _IsRunTrans = false; //事务运行标识
private string _SQLiteConnString = null; //连接字符串
private bool _AutoCommit = false; //事务自动提交标识 public string SQLiteConnString
{
set { this._SQLiteConnString = value; }
get { return this._SQLiteConnString; }
} public CSQLiteHelper(string dbPath)
{
this._dbName = dbPath;
this._SQLiteConnString = "Data Source=" + dbPath;
} /// <summary>
/// 新建数据库文件
/// </summary>
/// <param name="dbPath">数据库文件路径及名称</param>
/// <returns>新建成功,返回true,否则返回false</returns>
static public Boolean NewDbFile(string dbPath)
{
try
{
SQLiteConnection.CreateFile(dbPath);
return true;
}
catch (Exception ex)
{
throw new Exception("新建数据库文件" + dbPath + "失败:" + ex.Message);
}
} /// <summary>
/// 创建表
/// </summary>
/// <param name="dbPath">指定数据库文件</param>
/// <param name="tableName">表名称</param>
static public void NewTable(string dbPath, string tableName)
{ SQLiteConnection sqliteConn = new SQLiteConnection("data source=" + dbPath);
if (sqliteConn.State != System.Data.ConnectionState.Open)
{
sqliteConn.Open();
SQLiteCommand cmd = new SQLiteCommand();
cmd.Connection = sqliteConn;
cmd.CommandText = "CREATE TABLE " + tableName + "(Name varchar,Team varchar, Number varchar)";
cmd.ExecuteNonQuery();
}
sqliteConn.Close();
}
/// <summary>
/// 打开当前数据库的连接
/// </summary>
/// <returns></returns>
public Boolean OpenDb()
{
try
{
this._SQLiteConn = new SQLiteConnection(this._SQLiteConnString);
this._SQLiteConn.Open();
return true;
}
catch (Exception ex)
{
throw new Exception("打开数据库:" + _dbName + "的连接失败:" + ex.Message);
}
} /// <summary>
/// 打开指定数据库的连接
/// </summary>
/// <param name="dbPath">数据库路径</param>
/// <returns></returns>
public Boolean OpenDb(string dbPath)
{
try
{
string sqliteConnString = "Data Source=" + dbPath; this._SQLiteConn = new SQLiteConnection(sqliteConnString);
this._dbName = dbPath;
this._SQLiteConnString = sqliteConnString;
this._SQLiteConn.Open();
return true;
}
catch (Exception ex)
{
throw new Exception("打开数据库:" + dbPath + "的连接失败:" + ex.Message);
}
} /// <summary>
/// 关闭数据库连接
/// </summary>
public void CloseDb()
{
if (this._SQLiteConn != null && this._SQLiteConn.State != ConnectionState.Closed)
{
if (this._IsRunTrans && this._AutoCommit)
{
this.Commit();
}
this._SQLiteConn.Close();
this._SQLiteConn = null;
}
} /// <summary>
/// 开始数据库事务
/// </summary>
public void BeginTransaction()
{
this._SQLiteConn.BeginTransaction();
this._IsRunTrans = true;
} /// <summary>
/// 开始数据库事务
/// </summary>
/// <param name="isoLevel">事务锁级别</param>
public void BeginTransaction(IsolationLevel isoLevel)
{
this._SQLiteConn.BeginTransaction(isoLevel);
this._IsRunTrans = true;
} /// <summary>
/// 提交当前挂起的事务
/// </summary>
public void Commit()
{
if (this._IsRunTrans)
{
this._SQLiteTrans.Commit();
this._IsRunTrans = false;
}
} }
}

此时运行会报错,

警告  所生成项目的处理器架构“MSIL”与引用“System.Data.SQLite”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。请考虑通过配置管理器更改您的项目的目标处理器架构,以使您的项目与引用间的处理器架构保持一致,或者为引用关联一个与您的项目的目标处理器架构相符的处理器架构。

修改项目属性:x86。

再次运行,无误。

VS中C#连接SQLite数据库处理器架构“x86”不匹配的问题的更多相关文章

  1. 所生成项目的处理器架构“MSIL”与引用“Microsoft.AspNet.Scaffolding.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=x86”的处理器架构“x86”不匹配。

    生成成功后: 3>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): ...

  2. 所生成项目的处理器架构“MSIL”与引用“***”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。请考虑通过配置管理器...

    警告:所生成项目的处理器架构“MSIL”与引用“***”的处理器架构“x86”不匹配.这种不匹配可能会导致运行时失败.请考虑通过配置管理器更改您的项目的目标处理器架构,以使您的项目与引用间的处理器架构 ...

  3. C# 所生成项目的处理器架构“MSIL”与引用“Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86”的处理器架构“x86”不匹配。这种不匹配可能会导致运行时失败。

    这个问题一般都是Oracle.DataAccess的版本不兼容问题造成的. 解决办法: 1.把Oracle.DataAccess.dll文件拿到C盘或D盘的安装文件的地方进行搜索. 2.会出现在pro ...

  4. Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表,以及同步和异步执行模式)

    系列文章导航 Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表) Adobe AIR中使用Flex连接Sqlite数据库(2)(添加,删除,修改以及语句参数) Adobe ...

  5. VS2010连接SQLite数据库

    Visual studio 2010及以上版本,连接SQLite数据库 1.在Sqlite开发站点下载SQLite的.exe安装包 Ctrl+F搜索这条语句:This is the only setu ...

  6. Python3实现连接SQLite数据库的方法

    本文实例讲述了Python3实现连接SQLite数据库的方法,对于Python的学习有不错的参考借鉴价值.分享给大家供大家参考之用.具体方法如下: 实例代码如下: ? 1 2 3 4 5 6 7 8 ...

  7. 一起学微软Power BI系列-使用技巧(6) 连接Sqlite数据库

    好久没有研究Power BI了,看到高飞大神弄的东西,太惭愧了.今天有个小东西,数据在Sqlite里面,想倒腾到Power BI Desktop里面折腾一下,结果发现还不直接支持.所以只好硬着头皮上去 ...

  8. VS2010上连接SQLite数据库

    VS2010连接SQLite数据库 Visual studio 2010及以上版本,连接SQLite数据库 1.在Sqlite开发站点下载SQLite的.exe安装包 Ctrl+F搜索这条语句:Thi ...

  9. Delphi 2010下使用sqlitesimpledelphi连接SQLite数据库及中文乱码问题的解决

    应女朋友的要求,要写一款销售管理的软件.用于管理服装店每天的销售记录,已及管理服装店的客户,并对客户进行生日提醒 因为之前使用C#写过一款家庭管理软件,主要是自己用,所以使用了服务器型数据库MySQL ...

随机推荐

  1. Sql Server 2016数据库生成带数据的脚本

    步骤:右键点击对应数据库->任务->生成脚本 在弹出的会话框中选择需要的对象,点击下一步,在设置和编写脚本选项中,点开高级按钮(如图)选择架构和数据点击确定就可以了. 提醒:如果你在数据库 ...

  2. 《OpenCL异构并行编程实战》第十二至十四章

    ▶ 第十二章,在其他语言中使用 OpenCL ● JOCL(Java Building for OpenCL),PyOpenCL ● 一个 PyOpenCL 的例子代码,需要 pyopencl 包 i ...

  3. js 实现数组深度copy

    1. slice() slice() 方法可从已有的数组中返回选定的元素.arrayObject.slice(start,end) ,返回一个新的数组,包含从 start 到 end (不包括该元素) ...

  4. Python运维开发基础04-语法基础

    上节作业回顾(讲解+温习90分钟) #!/usr/bin/env python3 # -*- coding:utf-8 -*- # author:Mr.chen # 仅用列表+循环实现"简单 ...

  5. Marshaller根据对象生成xml文件

    创建Girl.java类 import java.util.List; import javax.xml.bind.annotation.*; @XmlAccessorType(XmlAccessTy ...

  6. word2vec 细节解析1

    count.extend(collections.Counter(list1).most_common(2))表示:使用collections.Counter统计list1列表重单词的频数,然后使用m ...

  7. 96. Unique Binary Search Trees (Tree; DP)

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  8. 使用mybatis提供的各种标签方法实现动态拼接Sql。这里演示where标签和if标签实现使用姓名的模糊查询和性别查询用户列表,当用户没有选择姓名以及性别时查询出所有的记录。

    1.需求: 使用姓名的模糊查询和性别查询用户列表,当用户没有选择姓名以及性别时查询出所有的记录. 2.在UserMapper接口中定义方法: public List<User> findU ...

  9. eclipse中的.project 和 .classpath文件的具体作用(综合):

    .project是项目文件,项目的结构都在其中定义,比如lib的位置,src的位置,classes的位置 .classpath的位置定义了你这个项目在编译时所使用的$CLASSPATH 这些文件你用文 ...

  10. [Selenium] 在Grid模式下打印出当前Case是在哪台Node上运行

    AAAbstractFlow() public void getComputerNameOfNode(WebDriver driver){ String CIHub = Environment.get ...