Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C#

SQLite GUI

Rate me:
Please Sign up or sign in to vote.
3.94/5 (26 votes)
10 Mar 2007CPOL1 min read 220.8K   9.8K   96   32
A GUI for SQLite in .NET
Screenshot - SQLiteGUI.gif

Introduction

This article describes how to create, insert, update SQLite database from GUI.

Description

SQLite GUI is a simple GUI for creating a new SQLite database and opening an existing SQLite database. It can also create, delete and update tables in the database. All the available tables in the database are shown. The records of various types including BLOB are displayed in the DataGridView. And the data in the DataGridView can be printed. The schema for all the available tables is displayed.

Dependencies

The SQLite.NET assembly is available here. Add the reference SQLite.Net.dll to the project and use the namespace Finisar.SQLite to work with SQLite.

Finisar.SQLite

Finisar.SQLite is an ADO.NET Data Provider for accessing SQLite-Databases using the .NET-Framework. In SQLite, a complete database is stored in a single disk file. SQLite is zero-configuration - no setup or administration needed. SQLite itself is "a small C library that implements a self-contained, embeddable, zero-configuration SQL database engine" (quoted from the sqlite.org Website). The Finisar.SQLite Data Provider is an easy way to use the SQLite-Database in .NET languages like C# and VB.NET.

Sample Code

C#
try
{
      //Connection string 
      string connString = String.Format("Data Source={0};New=False;Version=3", DB_NAME);
      
      //Connecting database
      SQLiteConnection sqlconn = new SQLiteConnection(connString);
      
      //Open the connection
      sqlconn.Open();

      //Query
      string CommandText = "Select name from sqlite_master;";

      //SQLiteDataAdapter to fill the DataSet
      SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(CommandText, sqlconn);
      dataAdapter.Fill(ds);

      //Get the collection of rows from the DataSet
      DataRowCollection dataRowCol = ds.Tables[0].Rows;

      //Add the tables available in the DB to the combo box
      foreach (DataRow dr in dataRowCol)
      {
          tablecombobox.Items.Add(dr["name"]);
      }
      
      //Close the Connection
      sqlconn.Close();

}              
catch (SQLiteException sqlex)
{
    MessageBox.Show(sqlex.Message);
}

To Do

Update cannot be performed on table without primary key. The SelectCommand must also return at least one primary key or unique column. If none are present, an InvalidOperation exception is generated, and the commands are not generated. The alternative way is create select, insert and update command for that particular table. Refer to MSDN. It will be available in the next version of SQLite GUI.

History

  • 10th March, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCannot open new db Pin
Member 1271015929-Aug-16 20:11
Member 1271015929-Aug-16 20:11 
SuggestionRe: Cannot open new db Pin
Member 24433062-Nov-17 11:08
Member 24433062-Nov-17 11:08 
Indeed it uses an old version of (Finisar) SQLite.Net-DLL and SQLite3.DLL itself was missing.
I see several Posts here about this.

However the easiest way to get it working is to:
1. remove old SQLite reference and DLL
2. add NuGet package SQLite
3. change Use statements to now use System.Data.SQLite;
4. Maybe change the File-filter to all supported formats:
C#
opnfiledlg.Filter = "SQLite Files (*.db, *.db3, *.sqlite, *.sqlite3)|*.db; *.db3;*.sqlite;*.sqlite3|All Files(*.*)|*.*";

5. Recompile
6. enjoy

However there are several cleanups possible, unfinished code fragments and unused forms. So enough to do if one wants to.

Hope this helps.
QuestionWorked as expected Pin
Nueman16-Mar-16 17:47
Nueman16-Mar-16 17:47 
QuestionUpdates for .NET 4.5.1 ? Pin
kiquenet.com31-Jan-14 4:36
professionalkiquenet.com31-Jan-14 4:36 
GeneralMy vote of 2 Pin
Marco Bertschi14-Jun-13 2:07
protectorMarco Bertschi14-Jun-13 2:07 
QuestionMultiple User Access To SQLite DB? Pin
Fatih BURAL14-Sep-12 9:32
professionalFatih BURAL14-Sep-12 9:32 
AnswerRe: Multiple User Access To SQLite DB? Pin
adriancs21-Oct-12 19:10
mvaadriancs21-Oct-12 19:10 
GeneralRe: Multiple User Access To SQLite DB? Pin
Fatih BURAL10-Nov-12 10:09
professionalFatih BURAL10-Nov-12 10:09 
GeneralRe: Multiple User Access To SQLite DB? Pin
jbmckim30-Nov-12 11:58
jbmckim30-Nov-12 11:58 
GeneralRe: Multiple User Access To SQLite DB? Pin
adriancs30-Nov-12 12:54
mvaadriancs30-Nov-12 12:54 
GeneralWindows 7 Pin
jimmygyuma13-Nov-09 10:49
jimmygyuma13-Nov-09 10:49 
GeneralRe: Windows 7 Pin
kazmirci23-Dec-09 21:39
kazmirci23-Dec-09 21:39 
GeneralRe: Windows 7 Pin
Member 1223765417-Apr-16 23:32
Member 1223765417-Apr-16 23:32 
GeneralExcellent Pin
loyal ginger6-Oct-09 6:11
loyal ginger6-Oct-09 6:11 
GeneralRe: Excellent Pin
Udhaya Kumar.D22-Nov-09 22:53
Udhaya Kumar.D22-Nov-09 22:53 
GeneralUpdate problem Pin
jimmygyuma13-Jun-09 7:38
jimmygyuma13-Jun-09 7:38 
GeneralProblem Pin
Zergushonok28-Oct-08 5:49
Zergushonok28-Oct-08 5:49 
GeneralRe: Problem Pin
Udhaya Kumar.D4-May-09 6:23
Udhaya Kumar.D4-May-09 6:23 
QuestionReadonly Mode Pin
cawoodm17-Sep-08 9:49
cawoodm17-Sep-08 9:49 
AnswerRe: Readonly Mode Pin
Udhaya Kumar.D30-Sep-08 5:25
Udhaya Kumar.D30-Sep-08 5:25 
GeneralPassword Protection Pin
DaveHoganIW3-Dec-07 9:09
DaveHoganIW3-Dec-07 9:09 
Generaluse System.Data.SQLite in the program Pin
VirusCamp12-Jun-07 20:33
VirusCamp12-Jun-07 20:33 
GeneralRe: use System.Data.SQLite in the program Pin
VirusCamp12-Jun-07 20:42
VirusCamp12-Jun-07 20:42 
GeneralA little problem Pin
nemopeti24-Mar-07 23:12
nemopeti24-Mar-07 23:12 
GeneralRe: A little problem Pin
Udhaya Kumar.D25-Mar-07 21:55
Udhaya Kumar.D25-Mar-07 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.