插入和更新不更改数据库(sdf) [英] Insert and update doesn't change database (sdf)

查看:353
本文介绍了插入和更新不更改数据库(sdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,将数据保存到名为Settings.sdf的数据库。我有几个文件:

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

UPDATE INSERT INTO 查询我不会更新我的数据库( Settings.sdf ),只更改缓存文件中的数据(无论什么地方)。我正确使用所有 SqlCeCommands 。例如:

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?

推荐答案

您可以调整数据库路径, / p>

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


  1. 调整:

  1. 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))
    {
    ...
    }
    

    这篇关于插入和更新不更改数据库(sdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆