http://www.cnblogs.com/xianyin05/archive/2012/12/23/2829905.html

using Models;
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Diagnostics;
using System.Linq;
using System.Text; namespace Demo2
{
class Program
{
static void Main(string[] args)
{
//Program p = new Program();
SqliteDataContext db = new SqliteDataContext(@"Data Source=MyDatabase.sqlite;Version=3;"); //创建连接
//var str = db.highscores.Where(u=>u.score>3000).ToList();
db.Log = Console.Out;
var temp1 = db.GetTable<highscores>().ToList(); var temp = db.GetTable<highscores>();
var result = from n in temp select n;
foreach (var item in result)
{
Console.WriteLine(item.name);
} Console.ReadKey();
} //数据库连接
SQLiteConnection m_dbConnection; public Program()
{
createNewDatabase();
connectToDatabase();
createTable();
fillTable();
printHighscores();
} //创建一个空的数据库
void createNewDatabase()
{
SQLiteConnection.CreateFile("MyDatabase.sqlite");
} //创建一个连接到指定数据库
void connectToDatabase()
{
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
} //在指定数据库中创建一个table
void createTable()
{
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
} //插入一些数据
void fillTable()
{
string sql = "insert into highscores (name, score) values ('Me', 3000)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery(); sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
} //使用sql查询语句,并显示结果
void printHighscores()
{
string sql = "select * from highscores order by score desc";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
}
Console.ReadLine();
}
}
}
using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data.SQLite;
using System.Linq;
using System.Text; namespace Demo2
{
public class SqliteDataContext : DataContext
{
public SqliteDataContext(string connection, MappingSource mappingSource) :
base(connection, mappingSource)
{
}
public SqliteDataContext(IDbConnection connection, MappingSource mappingSource) :
base(connection, mappingSource)
{
}
public SqliteDataContext(string connectionString) :
base(new SQLiteConnection(connectionString))
{
}
public SqliteDataContext(IDbConnection connection) :
base(connection)
{
} //public virtual DbSet<highscores> highscores { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text; namespace Models
{
[Table(Name = "highscores")] //特性表示将highscores类与数据库中名称为highscores的表
public class highscores
{
//[Column(IsPrimaryKey =true)]
[Column] //特性则对应数据库中的列
public string name { get; set; } [Column]
public int score { get; set; }
}
}

linq连接sqlite数据库(linq to sqlite) .net3.5的更多相关文章

  1. SQLite实现数据库的储存2+SQLite数据库可视化工具SQLite Stadio

    今日所学 SQLite实现数据库的储存 查看数据库的两种方法 Android 中 SQLite 数据库的查看 - woider - 博客园 SQLite Studio安装教程 [SQLite]可视化工 ...

  2. Android Sqlite数据库相关——实现 Sqlite 数据库版本升级

    继承SQLiteOpenHelper类后,实现其中的onUpgrade 方法 @Override public void onUpgrade(SQLiteDatabase db, int oldVer ...

  3. Sqlite在.NET下的使用和Sqlite数据库清理

    原文:Sqlite在.NET下的使用和Sqlite数据库清理 Sqlite 是一款轻量级的关系型数据库,她的好处我就不详细道来了.本文的初衷是为.net平台的使用者提供帮助. Sqlite有专门为VS ...

  4. SQLite数据库入门教程

    SQLite数据库入门教程 SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同, ...

  5. Andoird - SQLite 数据库 基础教程

    链接来源 http://www.tutorialspoint.com/android/android_sqlite_database.htm SQLite是一个开源的SQL数据库,这个数据库把数据存储 ...

  6. SQLite 数据库介绍和基本用法

    Ø  简介 SQLite 是一款轻量级的关系型数据库,同时也是一种嵌入式数据库,与 Oracle.MySQL.SQL Server 等数据库不同,它可以内嵌在程序中,是程序中的一个组成部分.所以,经常 ...

  7. C# SQLite数据库

    在客户端配置文件<configuration>节点下,添加: <connectionStrings> <add name="localdb" conn ...

  8. SQLite数据库下载、安装和学习

    SQLite 是一个开源的嵌入式关系数据库,实现自包容.零配置.支持事务的SQL数据库引擎. 其特点是高度便携.使用方便.结构紧凑.高效.可靠.与其他数据库管理系统不同,SQLite 的安装和运行非常 ...

  9. 讨论SQLite数据库损坏与修复

      版权声明:博客将逐步迁移到 http://cwqqq.com https://blog.csdn.net/cwqcwk1/article/details/45541409 昨晚,朋友和我反馈SQL ...

随机推荐

  1. iOS程序执行顺序和UIViewController 的生命周期(整理)

    说明:此文是自己的总结笔记,主要参考: iOS程序的启动执行顺序 AppDelegate 及 UIViewController 的生命周期 UIView的生命周期 言叶之庭.jpeg 一. iOS程序 ...

  2. gulp批量添加版本号

    要实现的理想效果: "/css/style.css" => "/dist/css/style.css?v=1d87bebe""/js/scrip ...

  3. 转载:Android SQLite数据库版本升级原理解析

    Android使用SQLite数据库保存数据,那数据库版本升级是怎么回事呢,这里说一下. 一.软件v1.0 安装v1.0,假设v1.0版本只有一个account表,这时走继承SQLiteOpenHel ...

  4. C++ 虚继承内存分配

    我们知道,虚继承的基类在类的层次结构中只可能出现一个实例.虚基类在类的层次结构中的位置是不能固定的,因为继承了虚基类的类可能会再次被其他类多继承. 比如class A: virtual T{} 这时T ...

  5. Mifare简介

    Mifare简介 MIFARE是NXP的知名品牌,是一个应用广泛的非接触式IC产品(13.56MHz非接触性辨识技术),一个典型的通信距离为10厘米,在全球有40多个不同的应用领域.有2.6亿个读写器 ...

  6. weex & web app & vue

    weex & web app & vue https://weex-project.io/tools/playground.html https://weex.apache.org/ ...

  7. 浅析_tmain() 与 main() 函数的区别

    _tmain()是为了支持Unicode所使用的main的一个别名,既然是别名,应该有宏定义过的,在<stdafx.h>里 #include <stdio.h> #indlud ...

  8. [bzoj] 3343 教主的魔法 || 带修改分块

    原题 长度为n的序列,有两种操作: 1.[l,r]区间每个数+w 2.询问[l,r]区间有多少个数>c 记录lazy数组即可. #include<cstdio> #include&l ...

  9. [codeforces] 359D Pair of Numbers

    原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...

  10. gdb server调试步骤

    编译gdb/gdbserver 编译arm-linux-gdb 下载gdb-7.12,解压缩进入目录 ./configure --target=arm-linux --program-prefix=a ...