Go to: Use SQLite ADO. Net to use the 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.. net independent release, but 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 based entirely on vs2005 and ADO. NET 2.0 is newly built and uses all ADO. net Framework. including full support for dbproviderfactory, Automatic Distributed Transaction calling, and extensive mode support. In addition, all classes are from ADO.. NET 2.0 base class 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
The space occupied by SQLite installation is negligible compared with SQL mobile. 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 work in a variety of Visual Studio 2005, including the experience version.

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 to pass in the SQLite kernel through an optimized pipeline in UTF-8 and UTF-16 encoding.

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, which will be very simple.

Provides allSource code. 100% free.
All encapsulated database sourcesCodeBoth public and commercial applications do not have any protocol constraints.

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

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

This providesProgramMore importantly, it provides support for ADO. Net vnext: http://sqlite.phxsoftware.com/blogs/sqlite/archive/2006/09/06/1949.aspx

2. Use SQLite in C #
1. Use Add references to reference system. Data. SQLite. dll in the bin directory of the SQLite ADO. 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 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 provides 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 ());
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.