Install and use sqllite in windows and call sqllite development in C #

Source: Internet
Author: User
Tags visual studio 2010

To install SQLite, you must first have an installation file. Since SQLite is an open source database, you can compile it on your own. I am relatively lazy and compiled it with others. Follow the steps below to install it. All are English websites. Please pay attention to this. Do not download the website incorrectly.

1. Install the SQLite Database

 
1) Open your browser and go to the SQLite homepage www.sqlite.org.
 
2) Click the download option at the top of the page to go To the download page.
 
3) scroll to "precompiled binaries for windows.pdf, select sqlite-shell-win32-x86-3071401.zip (item 1), and click Download. (You can download the corresponding version. I downloaded Windows 7 and 64-bit)
 
4) use the decompression tool to decompress the package. The zip file contains a sqlite3.exe file. You can use SQLite from the extracted file location. To run CLP in any directory, copy the file to the Windows system path. By default, the operating path in Windows is under the root partition (C: \ windwos \ System32 ). (Note: I downloaded sqlite3, so the command entered in cmd is sqlite3)
 
5) Open the Run window and Enter cmd to bring up the windows command line window. Enter sqlite3 directly in it
 
6) in the command line window, enter sqlite3 and press Enter. The SQLite command line prompt will appear. When the SQLite command line prompt appears, enter. Help, and a column similar to related commands will appear. Enter. Exit and exit the program.

 

:

As shown in, the installation is successful.
 

The above steps indicate that the installation has been completed, but it is a bit uncomfortable that after the installation is completed, the doscommand is run. However, there is a graphical interface, which I personally feel better, let's share it with you.

 

2. Visualized SQLite database management tools
 
In addition to the command line, there are many open-source and visualized SQLite database management tools on the network to manage SQLite databases. log on to https://sourceforge.net/#and use gooogle/Baidu. Input [SQLite] to find a large number of related tools, for example, SQLite database browser, SQLite administrator... and so on. I have tried a few. In comparison, I prefer SQLite administrator. This tool supports simplified Chinese characters, simple interfaces, and relatively simple database-related management operations. you can log on to http://sqliteadmin.orbmu2k.de/to download this tool.

 

3. Use SQLite database in Visual Studio 2010
 
Log on to http://sqlite.phxsoftware.com/download the latest version of ado.net 4.0 provider for SQLite. Download and unzip the package as an installation package. After clicking install, you can find the system in the installation directory. data. SQLite. DLL file. During installation, the DLL file is automatically registered to Visual Studio 2010 and can be referenced for the development environment (see figure ).

Just put the DLL in the project.

In Visual Studio 2010, select C # and create a new project sqliteview. For the main interface, see the following. This project allows you to browse, add, modify, and delete data records of SQLite database data tables.

The database metadata-type dataaccess code: using system; using system. data; using system. data. SQLite; namespace sqliteview {class dataaccess {sqliteconnection con; sqlitecommand command; Public dataaccess () {con = new sqliteconnection ("Data Source = test. db3 "); // test. db3 is in the DEBUG directory command = con. createcommand ();} // read the public datatable readtable (string tablename) {command. commandtext = "select * from" + tablename; Sqlitedataadapter da = new sqlitedataadapter (command); datatable dt = new datatable (tablename); DA. fill (DT); Return DT;} // modify the public bool updatetable (datatable srctable, string tablename) {bool isok = false; try {command. commandtext = "select * from" + tablename; sqlitedataadapter ODA = new sqlitedataadapter (command); sqlitecommandbuilder OCB = new sqlitecommandbuilder (ODA); ODA. insertcomma ND = OCB. getinsertcommand (); ODA. deletecommand = OCB. getdeletecommand (); ODA. updatecommand = OCB. getupdatecommand (); ODA. update (srctable); isok = true;} catch (exception ex) {} return isok ;}} the code for the ridu operation method is as follows: // refresh the data source private void refreshtable () {This. datagridview1.datasource = DBA. readtable ("testone");} // update the data source private void updatetable (datatable DT) {If (DT! = NULL) {If (DBA. updatetable (DT, "testone") {refreshtable (); MessageBox. show ("OK");} else MessageBox. show ("failed") ;}}// browse private void button#click (Object sender, eventargs e) {refreshtable () ;}// add or modify private void button2_click (Object sender, eventargs e) {datatable dt = This. datagridview1.datasource as datatable; updatetable (DT);} // Delete private void button3_click (Object sender, eventa RGS e) {datatable dt = This. datagridview1.datasource as datatable; datarowview rowview = This. datagridview1.currentrow. databounditem as datarowview; If (rowview! = NULL) {rowview. Row. Delete (); updatetable (DT );}}

Through the trial, we initially felt that the SQLite database had good support for the SQL language and had the relevant strong technical support (Development Team, community, Forum), fast running speed, high degree of attention, lightweight enough ..., among them, being lightweight is its biggest advantage and highlight.
 

This is the result of my use today. For your reference

 

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.