SQLite database installation, trial and programming testing hand-written http://www.ywtaoke.cn/taoke Network
Today, I tried the SQLite database and simply tested how to add, delete, and modify data tables. Now, the trial process is recorded as follows:
1. Install the SQLite Database
The so-called installation is very simple, LoginHttp://www.sqlite.org/You can run this file to create and manage SQLite databases through the command line (see ). You can run the [. Help] command to query the list of available commands. For details about the functions of each command, see the help documentation.
2. Visualized SQLite database management tool
In addition to the command line, there are many open-source and visualized SQLite database management tools on the network to manage SQLite databases.Https://sourceforge.net/Or another search engine (gooogle/Baidu) can input [SQLite] to find a large number of related tools, such as SQLite Database Browser and SQLite administrator. I have tried a few. In comparison, I prefer SQLite administrator. The tool interface supports simplified Chinese characters, simple interfaces, and relatively simple database-related management operations. you can log on to the tool.Http://sqliteadmin.orbmu2k.de/Download.
3. Use SQLite database in Visual Studio 2005
LoginHttp://sqlite.phxsoftware.com/Download the latest version of ADO. NET 2.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 2005 and can be referenced for the development environment (see figure ).
In Visual Studio 2005, 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.
TheCode:
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 located in the DEBUG directory.
Command = con. createcommand ();
}
// Read data
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 data table
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. insertcommand = 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 and 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, eventargs 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, Forums), fast operation speed, high popularity, and lightweight enough... among them, lightweight enough is its biggest advantage and highlight.
Share this simple trial note, hoping to attract everyone's attention to the SQLite database, and also hope to help friends who use the SQLite database for the first time. Thank you!
Download with source code:/Files/ysxlh/sqliteview.rar