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. 如何在 Eclipse 中使用插件构建 PHP 开发环境[转]

    原文出处: http://hykloud.com/2012/03/08/information_technology/how-setup-eclipse-php-pdt-remote-system-e ...

  2. 使用Unity做项目的时候,一些好的建议

    内容来自这个网站http://devmag.org.za/2012/07/12/50-tips-for-working-with-unity-best-practices/ ,我选取了目前我看得懂的一 ...

  3. 这是我见过最厉害的--智能代码生成器、html+js+底层+sql全都有、瓦特平台

    1:直接上图.图片有点多.我就没全部上传了. (demo.使用方法.数据库bak)下载:http://pan.baidu.com/s/1ntE5bDn 起源: 之前有好多人问我代码生成器的源码.我发了 ...

  4. C#泛型和泛型约束

    一.泛型: 所谓泛型,即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,从而实现更为灵活的复用. 二.泛型约束: 转自:http://ww ...

  5. tomcat启动后服务访问404

      .  解决办法: 在tomcat文件中有个work文件夹.其中,tomcat属于admin用户,work属于 admin用户 ,启动服务由admin用户启动. 但是发现work文件下的目录权限属于 ...

  6. Ubuntu下禁用笔记本自带键盘

    想要禁用笔记本自带键盘(Ubuntu)只要2条命令. 1. 打开终端,输入: xinput list ⎡ Virtual core pointer id=2 [master pointer (3)] ...

  7. Java系列学习说明

    最近要回顾以前的开发知识了,每天一个案例,争取早日成为一名合格的程序猿,现在就是猴娃子级别的.

  8. 关于usr/bin/ld: cannot find -lxxx问题总结(Qt编译错误cannot find -lGL)

    决定终结这个问题!(网上要想找到完整的解答实在太难了) http://blog.sciencenet.cn/blog-676535-541444.html 前两天手贱,把虚拟机玩崩溃了,只好重装虚拟机 ...

  9. kvm竟然抓不到kvm的tracepoint

    今天终于把kvm给搭起来了,打开了host机的tracepoint竟然一个都没有抓到,这是咋回事? 难道kvm的东西只有在启动的时候才会被抓到? 虚拟出来一块内存一块CPU,虚拟出来一个内存.感觉都好 ...

  10. Java分布式数据导出实践

    伴随业务发展日益剧增,对数据的要求越来越多也越来越高. 用户在浏览器发起导出请求--web服务器接收请求--请求后台获取数据--数据统计后生成excel或其他图标--响应给客户端 整个过程至少5步,才 ...