在C#中运用 SQLite
SQLite 是一个嵌入式的联系数据库系统,运用十分广泛。在一些数据量不大的运用 程序中,假如运用 SQLite可以极大的降低部署时的工作量。 要在C#中运用 SQLite也很基本,只要找一个C#的wrapper就可以了,例如,我运用的就是来自
http://sqlite.phxsoftware.com/ 的一个dll,System.Data.SQLite. 下载下来的文件是SQLite-1.0.65.0-setup.exe。只要安装一下就可以运用了,特别方便。该程序契合 ADO.NET的规范,并且支撑 Visual Studio的可视化表设计器。
打开Visual Studio 2008,新建一个Console Application,为此项目添加System.Data.SQLite的引用。添加一个数据库连接,此时可以发觉,新建连接中有了一个SQLite Database Connection,挑选此类型的数据连接,并且新建一个文件,
test.db3. 接下来在新数据库中添加一张表。
下面开始为此表建立一个Data Access类,以展示在C#中如何 运用 SQLite,可以想象,和操作其他数据库是几乎一样的,感谢ADO.NET的功劳。
最先是一个实体类 Book.cs:
public class Book
{
private int id;
private string bookName;
private decimal price;
public int ID
{
get { return id; }
set { id = value; }
}
public string BookName
{
get { return bookName; }
set { bookName = value; }
}
public decimal Price
{
get { return price; }
set { price = value; }
}
}
编写DAL类:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SQLite;
namespace ConsoleApplication1
{
public class BookDAL
{
public static bool Create(Book book)
{
try
{
using (SQLiteConnection conn = new SQLiteConnection("Data Sourc
相关文档:
刚开始很不习惯c#的风格,哎,先入为主啊,delphi习惯了,{}代替begin/end太扎眼。
属性方法的宣告和代码在一起,没有像delphi分interface/implementation,感觉太乱,都不知道一个class到底有几个方法。
每个属性和方法前面都要单独写private/protected/public,老天,c#是delphi之父设计的揶,怎么不学delphi写一个就行 ......
这是一个用c#控制台程序下, 用XmlDocument 进行XML操作的的例子,包含了查询、增加、修改、删除、保存的基本操作。较完整的描述了一个XML的整个操作流程。适合刚入门.net XML操作的朋友参考和学习。
假设有XML文件:books.xml
Xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<books>
< ......
一、建立网页
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<script language="javascript" type="text/javascript">
<!-- 提供给C#程序调用的方法 -->
function messageBox(message)
{
alert(message);
}
</script>
</head>
& ......
Internet 类
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
namespace DownData
{
class internet
{
&nb ......