0

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?

2 Answers 2

1

You can adjust your database path, you must set full path:

  1. Adjust with:

    string conString = "Data Source=" + Path.Combine(Your full path,"Settings.sdf");`
    
  2. Add ; at the end of your query

using (SqlCeCommand com = new SqlCeCommand("UPDATE Settings SET [Value] = (@loc) WHERE [Key] = 'Location';", con))
{
...
}
Sign up to request clarification or add additional context in comments.

3 Comments

add ; in the end of your query
I'm using WPF so it's bad to add Windows.Forms references. I can't use Application.StartupPath. The ';' at the end of the query is not necessery, but I've tried to use it and still nothing.
I have the same problem, but I added ; and using (SqlCeCommand com = new SqlCeCommand("UPDATE Settings SET [Value] = (@loc) WHERE [Key] = 'Location';", con)) { ... } but It doesn't work... Another idea?
0

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

Comments

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.