C # learning nine WPF apps using SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database

Before using SQLite, let's start by understanding the benefits of SQLite:

◇ Lightweight
First of all, it's a feature: lightweight. It must be the author of SQLite value this feature, even its logo is the use of "feathers" to show off its lightness.
Unlike the database software for SQLite and C/s mode, it is a database engine within the process, so there is no client and server for the database. With SQLite, you can use only one of its dynamic libraries to enjoy its full functionality. and the dynamic library size is also very small, in version 3.6.11 for example, under Windows 487KB, Linux under 347KB.
◇ Green Software
Another feature of SQLite is green: Its core engine itself does not rely on third-party software, and it does not need to be "installed". So you can save a lot of trouble when you deploy.
◇ Single File
The so-called "single file" is that all the information in the database (such as tables, views, triggers, etc.) is contained within a single file. This file can be copied to other directories or other machines, but also replicable.
◇ Cross-platform/portability
If the light supports the mainstream operating system, then there is nothing to brag about. In addition to the mainstream operating system, SQLite also supports a lot of unpopular operating systems. My personal interest is that it supports many embedded systems (such as Android, Windows Mobile, Symbin, Palm, VxWorks, etc.).
◇ in-memory databases (In-memory database)
These days, memory is getting cheaper, and many ordinary PCs are starting to measure memory in gigabytes (not to mention the server). At this point, SQLite's memory database features are becoming more usable.
The SQLite API does not differentiate whether the current operating database is in memory or in a file (for storage media is transparent). So if you think that disk I/O can be a bottleneck, consider switching to memory mode. When switching, the operation of the code of SQLite basically do not change, as long as the beginning of the file load to memory, the end of the memory of the database dump back to the file is OK.

Here are some specific steps you should take to use it:

1. Download System.Data.SQlite.dll from SQlite website

Website: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

This dynamic link library requires a Microsoft Visual C + + Runtime library that requires you to have Visual C + + runtime, you can view in the Control Panel program, if not, then download S ' teup version, If you already have one, download the static version. It is also important to note that when downloading the file is running in the X64 system or the X32 system, and in its own program is to adjust the corresponding schema, or it will run out of file format error.

2. With this you can reference the library in Visual Stidio.

3. Here are some C # statements that manipulate SQLite:

                Sqliteconnection con = new Sqliteconnection ("Data source=record.sqlite;                version=3; "); Con.                Open ();                Sqlitecommand cmd = new Sqlitecommand (); Cmd.                Connection = con;                Boolean testtableexists = false;                Cmd.commandtext = "SELECT * from Sqlite_master WHERE type= ' table ' and name= ' informations '"; using (Sqlitedatareader dr = cmd. ExecuteReader ()) {if (Dr.                    Read ()) {testtableexists = true; }} if (!testtableexists) {string sql= "CREATE TABLE Info                    Rmations (Website nvarchar (+), UserName nvarchar (+), password nvarchar (30)) ";                    Sqlitecommand command = new Sqlitecommand (sql, con); Command.                    ExecuteNonQuery ();                MessageBox.Show ("OK"); } string sqls = String. Format("INSERT into informations (Website, userName, password) VALUES (' {0} ', ' {1} ', ' {2} ')", Txwebsite.text,txusername.text, Txpassword.                Text);                Sqlitecommand commands = new Sqlitecommand (Sqls, con); Commands.                ExecuteNonQuery ();                MessageBox.Show ("OKs"); Con. Close ();

  

C # learning nine WPF apps using SQLite database

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.