Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Winform and a SQLite DataBase I have installed the SQLite NuGet and Reference to SQLite. I am get this error
An unhandled exception of type 'Finisar.SQLite.SQLiteException' occurred in SQLite.NET.dll

Additional information: no such table: VacTable


I can see the DataBase when I test my query in a SQLite query editor.

This is my First SQLite app.

code:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;



namespace Vacation_Time_3._3
{
    public partial class Form1 : MaterialSkin.Controls.MaterialForm
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string sql = "Select * from VacTable";
            DataAccess.ExecuteSQL(sql);
            DataTable dt = DataAccess.GetDataTable(sql);
            gridControl1.DataSource = dt;

        }
    }
    }



Class:

C#
<pre>using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Finisar.SQLite;
//using System.Data.SQLite;

namespace Vacation_Time_3._3
{
    //////SQLite Edition
    class DataAccess
    {

        // Connection String for  SQlite Edition
        static string _ConnectionString = @"Data Source=VacDB;Version=3;New=False;Compress=True";
        //Data Source=DemoT.db;Version=3;New=False;Compress=True;

        // Use for ..exe.config file 
        //   static string _ConnectionString = Sqtlie_project_tutorial.Properties.Settings.Default.SqliteDBtestConnectionString1;




        static SQLiteConnection _Connection = null;
        public static SQLiteConnection Connection
        {
            get
            {
                if (_Connection == null)
                {
                    _Connection = new SQLiteConnection(_ConnectionString);
                    _Connection.Open();

                    return _Connection;
                }
                else if (_Connection.State != System.Data.ConnectionState.Open)
                {
                    _Connection.Open();

                    return _Connection;
                }
                else
                {
                    return _Connection;
                }
            }
        }

        public static DataSet GetDataSet(string sql)
        {
            SQLiteCommand cmd = new SQLiteCommand(sql, Connection);
            SQLiteDataAdapter adp = new SQLiteDataAdapter(cmd);

            DataSet ds = new DataSet();
            adp.Fill(ds);
            Connection.Close();

            return ds;
        }

        public static DataTable GetDataTable(string sql)
        {
            Console.WriteLine(sql);
            DataSet ds = GetDataSet(sql);

            if (ds.Tables.Count > 0)
                return ds.Tables[0];
            return null;
        }

        public static int ExecuteSQL(string sql)
        {
            SQLiteCommand cmd = new SQLiteCommand(sql, Connection);
            return cmd.ExecuteNonQuery();
        }
    }

}


Image of Query
[IMG]http://i64.tinypic.com/1567er7.jpg[/IMG]


[^]

What I have tried:

Hours of research, I can see the database when I test my query in a SQLite query editor.
Posted
Updated 30-Mar-18 6:00am
v4
Comments
Afzaal Ahmad Zeeshan 30-Mar-18 11:58am    
But the error says, "VacTable" is not found. Can you check what database you are trying to connect to and it is the same one that you are using in the query?
Richard MacCutchan 30-Mar-18 11:59am    
Look again at the error message. It is telling you that the database does not contain a table called "VacTable". Use the command line sqlite3 shell to check the database.

1 solution

Check the path to the database, since you don't specify any in your connections string:
static string _ConnectionString = @"Data Source=VacDB;Version=3;New=False;Compress=True";
the file will be loaded from the current directory, which may not be the same as the folder you expect - remember that C# projects generally have at least two binary folders: bin/debug and bin/release so you may be reading the wrong one.

In any case, it's a bad idea to keep your data with your executable: in production the app will be installed under "Program Files" which is read only without admin access in modern OSes, so what works in dev, can fail in prod. See here: Where should I store my data?[^] - it shows some safer places to keep it.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900