Home > C#, Code Snippets, SQL > Your first SQLite program on .NET

Your first SQLite program on .NET

 

  1. Refer the System.Data.SQLite.dll file in your project
  2. Now you should be able to do this – using System.Data.SQLite;
  3. Now you should be able to use ADO.NET statements in your project. Eg: SQLiteDataAdapter, SQLiteConnection etc.

 

Here goes a sample code for C#:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using System.Data.SQLite;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            string strCon = "Data Source=C:\\your_path_to_file\\msgBC.s3db;Version=3;";
            string qry = "SELECT User, Message FROM tbl_Messages"; //your query
 
            SQLiteDataAdapter da = new SQLiteDataAdapter(qry, strCon);
 
            DataSet ds = new DataSet();
            da.Fill(ds);
 
            dataGridView1.DataSource = ds.Tables[0]; // I use a grid to show data
 
        }
    }
}
VN:F [1.9.18_1163]
Rating: 5.0/5 (1 vote cast)
Your first SQLite program on .NET, 5.0 out of 5 based on 1 rating

No related posts.

Categories: C#, Code Snippets, SQL