Using SQLite ADO. Net to use SQLite database in. Net (C #)

Source: Internet
Author: User
Tags password protection

[Reprint]
1. About SQLite ADO. net
System. Data. SQLite
Is an enhanced version of the original SQLite.
It will be a complete replacement of the original sqlite3.dll (you can even rename it as sqlite3.dll). It does not need to be linked to. net
During runtime, it can be released independently from. net. However, it is embedded with a complete ADO. NET 2.0 engine, providing complete support for development.

The following is a brief introduction to its features:

Complete ADO. NET 2.0 implementation
The entire project is completely built based on vs2005 and ADO. NET 2.0, using all ADO. net
New features of the framework, including full support for dbproviderfactory, Automatic Distributed Transaction calling, and extensive mode support. In addition, all classes are from ADO. net
The base class of 2.0 is inherited.

Supports the complete and streamlined. NET Framework and
C/C ++
This library is 100% compatible with the original sqlite3.dll and can be developed using an unmanaged C/C ++ when it does not need to be linked to the. NET runtime.

Portable database files
Unencrypted SQLite database files can be used freely across platforms and processors, including non-Windows platforms.
Encrypted databases can be used on all Windows platforms.

Reliable speed, faster than most other embedded databases, including SQL Server mobile
SQLite 'installation space relative to SQL
Mobile is negligible. It consumes less memory during running and generates a smaller database.

Database Encryption
The entire database file can be encrypted. Binary and plaintext passwords are supported.

Supports Visual Studio 2005 Design
You can add an SQLite connection to Server Explorer,
Use the query designer to create a query statement and drag a table to a dataset! SQLite developers can use a variety of Visual Studio
2005.

The size of a single file re-deployment package is less than KB
The SQLite and ADO. net packages are bundled and compiled together. Pre-compiled binary files provide x86, IA64, x64
And arm versions.

Extensive SQL language support
SQLite supports most sql92 standards (see below). Supports named and unnamed parameters with UTF-8 and UTF-16
The encoding is passed into the SQLite kernel through an optimized pipeline.

User-Defined Functions and sorting
Fully supports user-defined functions and sorting methods, which means you can use your favorite. NET language to implement features not provided by SQLite.
All of this will be very simple.

All source code. 100% is provided for free.
The source code of all the encapsulated libraries is public. No protocol constraints are imposed on individual or commercial applications.

Home: http://sqlite.phxsoftware.com/

(Latest Version 1.0.38.0): http://sourceforge.net/project/showfiles.php? Group_id = 132486 & package_id = 145568

More importantly, this provider provides ADO. net
Vnext support: http://sqlite.phxsoftware.com/blogs/sqlite/archive/2006/09/06/1949.aspx

2. Use SQLite in C #
1. Reference SQLite ADO through Add references
System. Data. SQLite. dll in the bin directory of the. NET installation directory.

2. Create a database file: because it is always a 0-byte file, I/O can also be used (?!).

System. Data. SQLite. sqliteconnection. createfile (datasource );

3. Connect to the database

System. Data. SQLite. sqliteconnection conn = new system. Data. SQLite. sqliteconnection (connectionstring );

Connectionstring contains some database configuration information, such as database files and password opened by the database. You can use system. Data. SQLite. sqliteconnectionstringbuilder to create connectionstring.

4. Creating tables and reading data are not much different from access or ms SQL.

// Create a database file
String datasource = "H:/test. DB ";
System. Data. SQLite. sqliteconnection. createfile (datasource );
// Connect to the database
System. Data. SQLite. sqliteconnection conn = new system. Data. SQLite. sqliteconnection ();
System. Data. SQLite. sqliteconnectionstringbuilder connstr = new system. Data. SQLite. sqliteconnectionstringbuilder ();
Connstr. datasource = datasource;
Connstr. Password = "admin"; // set the password. SQLite ADO. Net implements database password protection.
Conn. connectionstring = connstr. tostring ();
Conn. open ();
// Create a table
System. Data. SQLite. sqlitecommand cmd = new system. Data. SQLite. sqlitecommand ();
String SQL = "CREATE TABLE test (username varchar (20), password varchar (20 ))";
Cmd. commandtext = SQL;
Cmd. Connection = conn;
Cmd. executenonquery ();
// Insert data
SQL = "insert into test values ('dotnetthink', 'mypassword ')";
Cmd. commandtext = SQL;
Cmd. executenonquery ();
// Retrieve data
SQL = "select * from test ";
Cmd. commandtext = SQL;
System. Data. SQLite. sqlitedatareader reader = cmd. executereader ();
Stringbuilder sb = new stringbuilder ();
While (reader. Read ())
{
SB. append ("username:"). append (reader. getstring (0). append ("\ n ")
. Append ("Password:"). append (reader. getstring (1 ));
}
MessageBox. Show (sb. tostring ());

========================================================== ========================

This article is reprinted. You must ensure that this article is complete and the original author information and the link to this Article are fully retained.

E-mail:Khler@163.com

QQ: 23381103

MSN:Pragmac@hotmail.com

Statement: Repost is only intended to spread knowledge, so that more people can enjoy the crystallization of wisdom.

If you have any objection, please do it nowContact me, And will be deleted immediately.

I sincerely apologize!

========================================================== ========================

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.