PS: Some small insights, do not do, but also hope that friends a lot of guidance.
Data persistence is worth the way data is stored, in. NET you can use session, cookie object to save user login state, Application object Configuration Application.
This article mainly explains the data local storage scheme.
DataSet class Operation explanation
Saving data in an XML file
Saving data based on SQLite lightweight database
Saving data based on an Access database
Save based on SQL Server database
1. Before explaining the data preservation program, briefly describe the dataset class in. NET, which is essentially an in-memory database that contains all of the tables, relationships, and constraints. A datasheet (DataTable) is very similar to a physical database table, consisting of a set of columns that contain a specific attribute, and may contain 0 or more rows of data. Each datasheet contains data columns (DataColumns) and rows of data (DataRows), as an example of a database table.
Let's compare the database with the DataSet class for a more intuitive display:
Database DataSet
|-Table |-datatable
|-line |-datacolumn
|-Column |-datarow
Ado. NET Technology
(hard disk) < ——————— > (memory)
Create a Musicds DataSet with a MUSICDT datasheet, add name, Path column, and set Name column as primary key.
DataSet ds = NewDataSet ("Musicds");
Datatabledt = newdatatable ("MUSICDT");//CREATE TABLE
Dt. Columns.Add (New DataColumn ("ID", typeof (int));//Add column Specify data type
Dt. Columns.Add (Newdatacolumn ("Name", typeof (String));//Add Column
Dt. Columns.Add (Newdatacolumn ("Path", typeof (String));//Add Column
datacolumn[] pk = newdatacolumn[] {dt. columns["Name"]};//Create a primary key array
Dt. Constraints.add (Newuniqueconstraint ("Pk_musiclist", PK [0]));//Add Constraint collection specify name and instance
Dt. PrimaryKey = pk;//Add primary key array
Ds. Tables.add (DT);//Add to DataSet
To add data in a dataset:
Ds. tables["MUSICDT"]. Rows.Add (Names[i], paths[i])//Parameter object type and number corresponds to the type and number of columns in the datasheet.
2. Call Method WriteXml () After the DataSet object is set up, storing the data in memory in the form of an XML file to the hard disk.
Ds. WriteXml (". \\info\\list.xml", Xmlwritemode.writeschema);
The first parameter of the method is the file store address, and the second object specifies how to store it.
Ds. ReadXml (". \\info\\list.xml", XmlReadMode.ReadSchema);
The corresponding method is invoked to read the XML file to the DataSet object.
3. The local storage scheme based on the SQLite database adapts to the user information store of the small application, and the advantage of other database storage schemes is that it does not need to install supporting files in the application environment, so it takes up less memory. The disadvantage is that the read-write speed is slower than other large databases, so it adapts to the user information store for small applications, and the security aspect is significantly better than the XML file.
Need to use the System.Data.SQLite namespace method in the development process
SQLite database support is copied to the program folder, so you do not have to install a specific database support program after the application is installed.
The way to use it is to download support programs and view development tools on its official website, as well as an example of Slqlite database development on the official web site.
And there is the sqlite at present seem to support only. NET2.0 development.
4. Applications developed based on an Access database require Microsoft Access program support after installation.
The advantage is that the access speed, memory low, the disadvantage is that when the file information is large, the access speed will be reduced, the amount of support data is limited. Suitable for C/s mode of small management system development.
Need to use the System.Data.OleDb namespace method in the development process
5. A use program based on SQL Server database development requires the appropriate version of SQL Server database support. The low version development Amount database files are automatically upgraded to the version that the database supports, and some configurations need to be manually modified from advanced down to low-level versions, and the detailed process is no longer explained here.
A bit is the speed of access, safe and reliable operation, the disadvantage is compared to the previous described several programs on the machine requirements.
Application to B/S model development of small and medium-sized applications.
The same level of database has MySQL, Oracle, etc. ...
Summary: Data persistence schemes based on XML, SQLite, Access, SQL Server can exchange data with DataSet objects under. Net.
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/extra/