First taste C # connect to local data storage SQLite

Source: Internet
Author: User
Tags sqlite database

I. Installation

SQLite is a lightweight database and an acid-compliant associated database management system. I am using http://sqlite.phxsoftware.com/(an Open Source ADO. net provider for the SQLite database engine) directly, and the download is an EXE.

Then reference system. Data. SQLite. dllProgramSet;

If you still want to use LINQ in SQLite, you also need to reference the system. Data. SQLite. LINQ. dll assembly;

 

Ii. Create a database

After the installation is complete, open Visual Studio and create a data connection. You can see that the data source has an SQLite parameter.

Create a connection, as shown in. The SQLite database is saved as a file.

Iii. Database Maintenance

You can maintain SQLite data in Vs, for example:

You can use functions similar to SQL query analyzer in Vs, for example:

4. hybrid mode

After the installation is complete, you can directly reference the project set.

System. Data. SQLite

System. Data. SQLite. LINQ

Two assemblies, because the assemblies are loaded in runtime 4.0. Therefore, you must configure the following parameters in APP. config.

 <? XML version = "1.0" encoding = "UTF-8" ?> 
< Configuration >
< Startup Uselegacyv2runtimeactivationpolicy = "True" >
< Supportedruntime Version = "V4.0" />
</ Startup >
</ Configuration >

5. My testsCode Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. LINQ;
Using System. text;
Using System. Windows. forms;
Using System. Data. SQLite;

NamespaceXg_demo
{
Public Partial ClassForm1: Form
{
PublicForm1 ()
{
Initializecomponent ();
}

Private   Void Button#click ( Object Sender, eventargs E)
{
// Connection string reference
// String strcon = "datasource = test. db3; pooling = true; failifmissing = false ";
// "Northwindef (SQLite)" connectionstring = "provider = system. data. SQLite; Metadata = schemas \ northwindefmodel. CSDL | schemas \ northwindefmodel. MSL | schemas \ northwindefmodel. SQLite. SSDL; provider connection string = 'data source = dB \ northwindef. db '"

String Strcon =   " Data Source = xg_database; pooling = true; Password = sa " ;
Sqliteconnection con =   New Sqliteconnection (strcon );
Sqlitecommand cmd =   New Sqlitecommand ( " Select * from student " , Con );
Sqlitedataadapter da =   New Sqlitedataadapter (CMD );
Datatable dt =   New Datatable ();
Da. Fill (DT );
Datagridview1.datasource = DT;
}
}
}

Learning Source: C # SQLite of local data storage solution

Download demo

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.