SQLite Installation and invocation

Source: Internet
Author: User
Tags sqlite connectionstrings

You want to replace the SQL Server database for the project because SQL Server is too large and my project is just a small desktop application.

Online search, found SQLite, is really a good thing, no need to install and deploy, the key is that customers do not have to use the computer installed on the database, the size of only 1M more, is what I want.

It took a half-day to replace the database of the project, and the SQL statements were basically available, and only the individual statements were modified. Make a simple record of the usage of SQLite.

First, SQLite installation

: http://www.sqlite.org/download.html I use Win7 32-bit, choose these two.

After downloading the decompression, put two pressurized files into the new SQLite folder on the C drive, or any other folder, as the installation path of SQLite.

If you use the DOS environment to configure the database and table structure, you need to use the Sqlite3 command, you need to configure Sqlite3.exe to the system environment variables, right-click Computer, properties, advanced system settings, environment variables, edit path, add C:\sqlite ,

That is, the installation path we established.

After adding, you can use CMD, enter Sqlite3, appear

That is to add the success, then we can use the DOS window to create a database and tables, including a variety of additions and deletions to change the operation. If you do not like DOS operations, you do not need to add environment variables, direct use of the visualizer.

Second, SQLite visualization tools

I personally like the visual operation, although there is no DOS operation "tall", but there are convenient tools why not? I searched, SQLite visualization tools are quite many, I made a paragraph, called SQLite Studio, feel can.

SQLite STUDIO:HTTPS://SQLITESTUDIO.PL/INDEX.RVT

Under Visual Tools, create a database and a table in a fool's style.

Third, SQLite Drive

After the database is created, the program needs to connect to the database because I use C #, so I also download the C # 32-bit driver.

Driver: Http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki, I'm used to using. NET 4.0, so I downloaded this

Install directly after download, and then in the program refer to the System.Data.SQLite.dll under the installation path, import the namespace:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Configuration;usingSystem.Data;usingSystem.Data.SqlClient; using  System.Data.SQLite; namespacedal{ Public classDal_login { private static string constr = system.configuration.configurationmanager.connectionstrings["sqlconnectionstring" ]. ConnectionString;   System.Data.DataSet DS=NewSystem.Data.DataSet (); Sqliteconnection sqlconn=Newsqliteconnection (); Sqlitecommand Sqlcomm=NewSqlitecommand (); Sqlitedataadapter SqlDa=NewSqlitedataadapter (); Sqlitecommandbuilder SCB=NewSqlitecommandbuilder ();  Public voidConn () {if(Sqlconn.state = =connectionstate.closed) {sqlconn=Newsqliteconnection (CONSTR);                Sqlconn.open (); Sqlcomm.connection=sqlconn; Sqlcomm.commandtype=CommandType.Text; }        }         Public voidClose () {sqlda.dispose (); SqlDa=NULL;            Sqlcomm.dispose (); Sqlcomm=NULL;            Sqlconn.dispose (); Sqlconn=NULL; }         PublicDataTable GetUserName () {Sqlcomm.commandtext="SELECT distinct UserName from Cmsuserinfo ORDER by UserName ASC";            SqlComm.Parameters.Clear (); Sqlda.selectcommand=Sqlcomm; Sqlda.fill (DS,"Mer_login_username"); Ds. tables["Mer_login_username"].            Clear (); Sqlda.fill (DS,"Mer_login_username"); returnDs. tables["Mer_login_username"]; }         Public intCheckuserinfo (stringNamestringPass) {Sqlcomm.commandtext="Select COUNT (*) from cmsuserinfo where UserName = @name and Userpass [email protected]";                SqlComm.Parameters.Clear (); varparas =NewSqliteparameter[] {NewSqliteparameter ("@name", name),NewSqliteparameter ("@pass", pass)};                SqlComm.Parameters.AddRange (paras); intn =int. Parse (Sqlcomm.executescalar ().                ToString ()); returnN; }    }}

To configure a connection string using app. Config:

 <?xml version= " 1.0  "  encoding= " utf-8   "?><configuration> <connectionStrings> <add name= " sqlconnectionstring  "   connectionString  = " data source=| datadirectory|\*.db; Pooling=true; Failifmissing=false   "  providerName  = " system.data.sqlite   "/> </connectionstrings></configuration> 

I like to put *.db into the application path, and the direct copy can be run on other computers. System.Data.SQLite.dll and *.db are the only two files in the client's computer folder to access the database, of course. NET 4.0 is required.

SQLite Installation and invocation

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.