idrisjafer
idrisjafer

Reputation: 735

Not able to insert data in SQLite using C#

My problem is I am not able to insert data into SQLite using C#. However I am able to select the records and retrive it using dataset. The SQLite database file is included in the solution directory and Build Action property of SQlite file is set to "Embedded Resource" in Visual Studio 2008. C# code is as follows :

 private void button2_Click(object sender, EventArgs e)
    {
        SQLiteConnection con = new SQLiteConnection("Data Source=MonitoringDB.s3db;Version=3;New=True;Compress=True;Synchronous=Off");
        SQLiteCommand cmdinsert = new SQLiteCommand("Insert into Parameters(Id,Day,Time,Parameter) values(1,1,1,15) ", con);
        con.Open();
        cmdinsert.ExecuteNonQuery();
        con.Close();
    }

Is something wrong with my code ?

Upvotes: 1

Views: 1330

Answers (1)

Nasreddine
Nasreddine

Reputation: 37788

You can't insert because the database is embedded in your EXE file. and you can't change embedded resources. What you can do is consider copying the resource out to disk on start up, if it doesn't already exist and work on that copy.

Upvotes: 5

Related Questions