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. gVim的 设置

    在.vimrc中添加以下代码后,重启vim即可实现按TAB产生4个空格:set ts=4  (注:ts是tabstop的缩写,设TAB宽4个空格)set expandtab TAB替换为空格::set ...

  2. json对象和java对象的相互转换方法(json-lib、jackson、fastjson、gson)

    一 使用json-lib包下的JSONObject和JSONArray转换 代码如下: package com.test.test; import java.util.ArrayList; impor ...

  3. BAD_ACCESS在什么情况下出现?如何调试BAD_ACCESS错误

    1. 访问一个僵尸对象,访问僵尸对象的成员变量或者向其发消息 死循环 2. 设置全局断点快速定位问题代码所在行 开启僵尸对象调试功能  

  4. 《数据结构与算法分析:C语言描述》复习——第八章“并查集”——并查集

    2014.06.18 14:16 简介: “并查集”,英文名为“union-find set”,从名字就能看出来它支持合并与查找功能.另外还有一个名字叫“disjoint set”,中文名叫不相交集合 ...

  5. python学习笔记十一:操作mysql

    一.安装MySQL-python # yum install -y MySQL-python 二.打开数据库连接 #!/usr/bin/python import MySQLdb conn = MyS ...

  6. 【Kernel Logistic Regression】林轩田机器学习技术

    最近求职真慌,一方面要看机器学习,一方面还刷代码.还是静下心继续看看课程,因为觉得实在讲的太好了.能求啥样搬砖工作就随缘吧. 这节课的核心就在如何把kernel trick到logistic regr ...

  7. Action参数和View、Json、重定向

    一.Action 1.Action参数: 普通参数.Model类.FormCollection (1).普通参数 Index(string name,int age)   框架会自动把用户请求的Que ...

  8. [Leetcode/Javascript] 461.Hamming Distance

    [Leetcode/Javascript] 461.Hamming Distance 题目 The Hamming distance between two integers is the numbe ...

  9. SQL 基础笔记(二):进阶查询

    本笔记整理自<SQL 基础教程>.<MySQL 必知必会>和网上资料.个人笔记不保证正确. 一.复杂查询 视图 将 SELECT 查询包装成一个虚拟表,该虚拟表就被称为视图.( ...

  10. 【转】TCP通信的三次握手和四次撒手的详细流程(顿悟)

    TCP(Transmission Control Protocol) 传输控制协议 三次握手 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位 ...