问题
I have a problem with saving data to database named Settings.sdf
. I have few files:
- Settings.sdf
- SettingsDataSet.xsd
- SettingsDataSet.Designer.cs
- SettingsDataSet.xsc
- SettingsDataSet.xss
If I tried use UPDATE
or INSERT INTO
queries I would not update my database (Settings.sdf
), only change data in cache file (whatever and wherever it is). I'm using correctly all SqlCeCommands
. For example:
string conString = "Data Source=Settings.sdf";
con = new SqlCeConnection(conString);
con.Open();
...
using (SqlCeCommand com = new SqlCeCommand("UPDATE Settings SET [Value] = (@loc) WHERE [Key] = 'Location'", con))
{
com.Parameters.AddWithValue("@loc", device.Location);
com.ExecuteNonQuery();
}
...
con.Close();
How manage this problem? Why this command doesn't update directly my database?
回答1:
You can adjust your database path, you must set full path:
Adjust with:
string conString = "Data Source=" + Path.Combine(Your full path,"Settings.sdf");`
Add
;
at the end of your query
using (SqlCeCommand com = new SqlCeCommand("UPDATE Settings SET [Value] = (@loc) WHERE [Key] = 'Location';", con))
{
...
}
回答2:
the changed maded in the sdf file in debug directory but when you run again the sdf will be created again, remove the create always and test again
来源:https://stackoverflow.com/questions/12072169/insert-and-update-doesnt-change-database-sdf