C # single-host Window program sqlite database implementation

Source: Internet
Author: User
Document directory
  • Database Analysis and selection
  • C # sqlite database implementation

In the past few days, a simple drug Query form application has been developed for a hospital.

Database Analysis and selection

Excel files as data sources

Highly restrictive and not suitable for queries, analysis, and other operations

 

Access Database

Access Management data interface and functionality is not strong

Mysql and SQL server

Functions are met, but you need to install

 

Finally, select the sqlite database.

C # sqlite database implementation

Step one download the sqlite database. net access component and install

Http://sourceforge.net/projects/sqlite-dotnet2/

 

Step Two: Create a project and add sqlite Access Components and sqlite database files

  

 

Step Three create a link to access the database

 public static DataTable GetAllBook()      {          DataTable dt = new DataTable();          try          {              SQLiteConnection conn = new SQLiteConnection("Data Source=db/Books.sqlite;");              conn.Open();              SQLiteCommand cmd = new SQLiteCommand(conn);              cmd.CommandText = "SELECT * FROM Book";              cmd.CommandType = CommandType.Text;              //Console.WriteLine(cmd.CommandText);              SQLiteDataReader dr = cmd.ExecuteReader();              if (dr.HasRows)              {                  dt.Load(dr);              }              else {                  //throw new NullReferenceException("No Record Available.");              }                dr.Close();              conn.Close();                                        }          catch (ArgumentException ae)          {              MessageBox.Show(ae.Message + " \n\n" + ae.Source + "\n\n" + ae.StackTrace + "\n\n" + ae.Data);          }          catch (Exception ex)          {              //throw new Exception(ex.Message);              MessageBox.Show(ex.Message + " \n\n" + ex.Source + "\n\n" + ex.StackTrace + "\n\n" + ex.Data);          }  

 

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.