1

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 ?

5
  • 2
    What errors or exceptions are you getting? Commented Oct 9, 2012 at 9:33
  • Is there any password in that file?? Commented Oct 9, 2012 at 9:35
  • Nothing wrong with your code but I never tried it on SQlite set to Embedded Resource. Commented Oct 9, 2012 at 9:37
  • @Danilo: I didnt get any exception as such. Commented Oct 9, 2012 at 9:38
  • @nikhil : there is no password in that file Commented Oct 9, 2012 at 9:39

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

then should I place my DB file in another folder?
Change the Build Action of the database file to Content and Copy to output Directory to Copy if newer this will copy your database to the output folder (where your compiled exe is) and you can work on that file (insert/select/delete).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.