简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM