About the operation of SQLite reading data in C #

Source: Internet
Author: User

Do a C # friend of a Get dataset function, not familiar with C #, collation, understand how to use

When mounting a table, use        
public static DataSet Query (string SQLString) { using (sqliteconnection connection = new Sqliteconnection ( connectionString)) { DataSet ds = new DataSet (); Try { connection. Open (); Sqlitedataadapter command = new Sqlitedataadapter (SQLString, connection); Command. Fill (ds, "DS"); } catch (System.Data.SQLite.SQLiteException ex) { throw new Exception (ex. Message); } return DS; Returned a DataSet } }

Application:

When mounting a form, use it directly.

Grd.datasource=query (SQL). Tables[0]

  

        Execute query statement, return sqlitedatareader//get return value with//</summary>//        <param name= "strSQL" > Query statement </param >        //<returns>SQLiteDataReader</returns> public static Sqlitedatareader ExecuteReader ( String strSQL)        {            sqliteconnection connection = new Sqliteconnection (connectionString);            Sqlitecommand cmd = new Sqlitecommand (strSQL, connection);            Try            {                connection. Open ();                Sqlitedatareader myreader = cmd. ExecuteReader ();                return myreader;            }            catch (System.Data.SQLite.SQLiteException e)            {                throw new Exception (e.message);            }        }

Application

            Sqlitedatareader sqldr = dbsqlite.executereader (sql); Sqlitedatareader needs to be quoted first, using System.Data.SQLite;            try {                 while (Sqldr.read ()) {                    int rn = SQLDR.GETINT32 (1);                    String Rname=sqldr.getvalue (0).  ToString (); Field Read                    if (rn = = 5)                    {                        //if (rname). Equals ("1"))                        //{                        //    str + = Sqldr.getvalue (2). ToString () + "yes" + "\ r \ n";                        }                        //else {                        //    str + = Sqldr.getvalue (2). ToString () + "no" + "\ r \ n";                        }                                            }            }catch            {                    }

  

  

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.