1

I have a c# winform project that supposes to save data to SQLite database, I've already used the dll properly and it runs without error, but I get an exception when trigger the method with buttonClick event

here the exception i got : Keyword not supported :'version'.

this the connection string:

"Data Source = Diary.db;Version = 3;New = False;Compress = True;"; 

and this the complete method :

private void AddToDbaseSQL3()
    {
        try{
            string query = "insert into Diary(title,date,mood,wheater,content)                                           
            values('"+TitleTextbox.Text+"','"
            +dateTimePicker.Value.Date.ToString("yyyy-MM-dd HH:mm")+"','"
            +MoodCombobox.SelectedItem+"','"
            +WheaterCombobox.SelectedItem+"','"
            +ContentTextbox.Text+"');";;
            SqlConnection connect2 =  new SqlConnection(connection2);
            SqlCommand cmd = new SqlCommand(query,connect2);
            SqlDataReader read;
            connect2.Open();
            read =  cmd.ExecuteReader();
            while(read.Read())
            {
               
            }
           
            MessageBox.Show("created");
            TitleTextbox.Text = "Title";
            TitleTextbox.ForeColor = SystemColors.ControlLight;
            ContentTextbox.Clear();
            connect2.Close();
           
        }catch(Exception e){
            MessageBox.Show(e.Message);
        }
    }

I've looked to this link: Keyword not supported: 'version'

and it said to change SqlConnection to SQLiteConnection but it ended with an error, can you tell what's is the right connection string ? or there is something wrong from my code/method? please tell me, thank you, I'm sorry because it's my first time using the SQLite

  • 1
    If you are using sqlite, you have to use the provider for it: SqliteConnection, SqliteCommand, etc. SqlConnection, etc., is only for MS SQL Server. – Crowcoder Jul 04 '20 at 12:12
  • what does your complete connection string node look like in the config file? – Rans Jul 04 '20 at 12:18

1 Answers1

0

SqlConnection from System.Data.SqlClient is for SQL Server.

You need an dedicated SQLite ADO.NET provider.

You can found the System.Data.SQLite provider from SQLite team here:

https://system.data.sqlite.org

Or you can use any libre or commercial provider.

You can also use the free and open-source SQLite ODBC driver that works fine and allow to use VS Visual Designers to create strongly typed ADO.NET DataSets, in addition to the use of OdbcConnection, OdbcCommand and so on:

http://www.ch-werner.de/sqliteodbc

C# Reading data from existing SQLite database