Today is the 18th day of my internship. I mainly learned how to operate the SQLite database in ASP. The basic operation is as follows:
- Add Reference System.Data.SQLite.dll (PS: In the Web page to find the appropriate version of the. NET Framework and the number of bits corresponding to the compression package, there will be the file).
- Include using System.Data.SQLite in the CS file where it resides;
- Defines two string variables: Constr, SQLSTR, respectively, for SQLite's connection string and SQL statement.
- Defines the SQLITECONNECTION variable conn, which is used to connect to the database.
- Conn.Open (); Connecting to a database
- Defines the Sqlitecommand variable.
- Perform the operation, can use ExecuteNonQuery, ExecuteReader, etc., this should depend on oneself demand.
- Conn.close (); Disconnecting a database
The specific code is as follows (it is an example of the number of rows in a statistic):
1 Public intCount ()/** * Total number of rows in the statistics * **/2 {3Sqliteconnection Conn =NewSqliteconnection (CONSTR)//set the string for the SqlConnection object connection database4 5Conn.Open ();//Open a connection to a database6 7 stringSqlstr ="Select COUNT (*) as Num from Tb_demo";8Sqlitecommand CMD =NewSqlitecommand (Sqlstr, Conn);9Sqlitedatareader Re = Cmd.executereader ();//reading data using the DataReader objectTen Re.read (); One intnum = Convert.ToInt32 (re["Num"]); A -Conn.close ();//to close a connection to a database - the returnnum; -}
Although the various operations on the data are not the same, but the approximate idea is the same, so you can follow the above example extrapolate. Hope that my small experience can help everyone's busy, thank you!