2014-08-01 ASP. NET in the operation of SQLite database--ado.net

Source: Internet
Author: User
Tags sqlite sqlite database

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:

    1. 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).
    2. Include using System.Data.SQLite in the CS file where it resides;
    3. Defines two string variables: Constr, SQLSTR, respectively, for SQLite's connection string and SQL statement.
    4. Defines the SQLITECONNECTION variable conn, which is used to connect to the database.
    5. Conn.Open (); Connecting to a database
    6. Defines the Sqlitecommand variable.
    7. Perform the operation, can use ExecuteNonQuery, ExecuteReader, etc., this should depend on oneself demand.
    8. 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!

  

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.