How to use SQLite with Visual Studio Project

This short article show you how to use SQLite with Visual Studio Project.

It is quite confusing when you have Compare SQL and SQLite. This article focus on SQLite.

You can use an open source tool to create the SQLite database db file and see the records.


Run the SqlCeToolbox. then you will get the tool in your Visual Studio.

To Create a Database using the tool

1.      Click on “Tools (menu item)”


2.      Click on “SQL Server Compact/SQLite Toolbox (menu item)”.


3.      Right click on “Add SQLite Connection… 


4.      Click on “Create… (button)” in “Add SQLite Connection”


5.      Type in the database name and click Save.


6.      Click on “Test Connection (text)” in “Add SQLite Connection” then click OK.



7.      Click on “mydb.db (SQLite) (tree view item)” to expand the database.


8.      Right click Table then click on “Build Table (beta)… “.


9.      After put in all the information you need then click on “Script! (text)” in “Build Table”.


10.   Click the Green Play (Run) button to create the table.



You can see now there is a Customer table created.



Install SQLite packages to the project

1.      Click on “Manage NuGet Packages for Solution… (menu item)”.


2.      Type SQLite in the Search box then you will see the SQLite package appear.


3.      Click Install.


4.      Click OK and you are done.



To insert the record into SQLite, the code as below

private static void WriteSQLite()


    using (SQLiteConnection conn = new SQLiteConnection(“data source=mydb.db”))


        using (SQLiteCommand cmd = new SQLiteCommand())


            string strSql = “INSERT INTO [Customer] ([Id],[CustName]) VALUES (1, ‘Ming’)”;

            cmd.CommandText = strSql;

            cmd.Connection = conn;





            // do something…







About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress ( till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net, Community and tagged , , , , , , , . Bookmark the permalink.

7 Responses to How to use SQLite with Visual Studio Project

  1. Martha says:

    Thanks for this article.
    When I try to add SQLite through NuGet, it seems to install correctly. I get a message saying, “Successfully installed ‘SQLite 3.12.2’ to SQLite_test”.
    However, System.Data.SQLite never shows up in the list of references for my project, and copying your code gives me the error, “The type or namespace name ‘SQLiteConnection’ could not be found”.
    I can go back into NuGet and see that it claims that SQLite is installed. I can un-install and re-install, getting success messages each time.
    Thank you for any help you can provide.

    • chanmingman says:

      Can you create another project or try this in another machine?

      • Thanks for the reply.

        I have created a new project on a different PC and I’m getting the same problem.
        NuGet Manager says that SQLite is installed, but it is not listed under my project’s references.

        packages.config contains the lines:

        So it seems like the NuGet installation did something, but the SQLite code is still giving me errors: “The type or namespace name ‘SQLiteConnection’ could not be found”.

      • I tried creating a new project on a different PC. I get the same behavior.

      • chanmingman says:

        Very strange, one of the possibility I can think of is you may select a different package in nugget. Maybe you can use the Step Recorder to record the steps and email to me.

      • Under Step 2 & 3 of “Install SQLite packages to the project”, you highlight and install “sqlite” with an icon that looks like a rounded square with 2 dots inside it and one dot outside to the upper-left corner. That’s what I have been trying to install without success.

        I eventually tried installing “System.Data.SQLite”, the first item in the list of results, with an icon that looks like a piece of paper and a quill. That seemed to do the trick for me. It added the reference to my project and I am able to insert records with the code you provided.

        Thank you for all your help with this!

  2. chanmingman says:

    Great to hear that. /Sometime this is the problem with Open Source 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.