XiaoHui.Net 笑汇程序员论坛Visual C++ 讨论区

   VC中如何执行SQL语句


页: [1]

龙主人2007-11-18 00:56
VC中如何执行SQL语句

我用CDatabase 类中的ExecuteSQL()这个函数执行了一个SQL的查询语句SELECT   department   FROM   xsjbxxb,可是这个函数又是没有返回值的,如何让选择的结果插入到组合框中呢?


XiaoHui2007-12-15 02:40
注意看 MSDN 的文档说明:
[quote]
ExecuteSQL does not return data records. If you want to operate on records, use a recordset object instead

Most of your commands for a data source are issued through recordset objects, which support commands for selecting data, inserting new records, deleting records, and editing records. However, not all ODBC functionality is directly supported by the database classes, so you may at times need to make a direct SQL call with ExecuteSQL.
[/quote]

ExecuteSQL 不提供记录返回。如果你要操作记录,使用 CRecordset。

龙主人2007-12-15 08:10
哦,谢谢啊,是不是把得到的结果用组合框中的Addstring()这个函数加进去就行啦

XiaoHui2007-12-15 13:14
对, 将取得的数据格式化后调用 AddString 插入就可以了. 或者使用 CB_ADDSTRING 消息.

龙主人2007-12-18 05:57
真是太感谢啦,问题已经解决啦

accessory2007-12-22 01:02
牛人好多啊,感觉自己白活了一辈子,做自己不想做的事情。学过一些C,但已荒废的差不多!自己的理想永远成为梦想!


查看完整版本: VC中如何执行SQL语句