从 MFC 应用程序连接到 SQL Server Compact Edition (.sdf)
我正在 Visual Studio 2008 中构建一个对纹理进行分类的 MFC 应用程序,我需要某种轻量级数据库来保存特征(只是一些双精度和字符串),这些特征可以是:
- 在不同计算机上与应用程序一起携带
- 能够执行查询 目前我正在研究 SQL Server Compact Edition ,
因为它很容易从 Visual Studio 创建(我也只需要一张表)。但我很难从 C++ 连接和更新数据库。
这是我在 MSDN 上找到的有关 C++ 和 SQLCE 的内容:
public:
void createSqlCeConnection(){
SqlCeConnection* myConnection = new SqlCeConnection();
myConnection->ConnectionString = "DataSource = blabla.sdf";
MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));
}
不幸的是,我对 .NET 应用程序的经验非常有限。
希望各位聪明人能告诉我是否走在正确的道路上,以及我应该添加哪些链接和包含内容才能与 C++ MFC 项目一起使用。
I'm building an MFC app in Visual Studio 2008 which classifies textures and I need some sort of lightweight database to hold the characteristics (just some doubles and strings) which can be:
- Carried around with the app on different computers
- Be able to perform queries on it from the app (searches , updates ,inserts ,etc)
Currently I'm looking into SQL Server Compact Edition because it was very easy to create from Visual Studio (I also need only one table). But I;m having a hard time connecting and updating the database from C++.
This is what I've found on MSDN regarding C++ and SQLCE:
public:
void createSqlCeConnection(){
SqlCeConnection* myConnection = new SqlCeConnection();
myConnection->ConnectionString = "DataSource = blabla.sdf";
MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));
}
Unfortunately my experience with .NET apps is pretty limited.
Hopefully you bright minds could tell me if I'm on the right path and what links and includes should I add for this to work with an C++ MFC projects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 C++ 应用程序,您需要使用 用于 SQL CE 的 OLE DB 提供程序。例如,请查看此处的代码片段 初始化会话(您可能必须显式单击“示例”部分中的“C++”选项卡)。
For C++ applications, you're going to want to use the OLE DB Provider for SQL CE. For example, take a look here for a code snippet on initializing a Session (you might have to explicitly click the C++ tab in the Examples section).