With CDatabase, can I send SQL without using CRecordSet?

爱⌒轻易说出口 提交于 2019-12-11 14:58:25

问题


When using the MFC class CDatabase to connect to a data source, is there any way to execute SQL statements without having to open a CRecordSet object? I ask because CRecordSet::Open() appears to throw an exception when I use it to call stored procedures that don't return anything - and there's no reason to expect results from, say, sp_delete_row.


回答1:


I use CDatabase::ExecuteSQL()

CDatabase database;
//database is connected somewhere
database.ExecuteSql("Drop table [users]");  // sql statement from little Johnny Drop tables



回答2:


You can execute a CCommand directly to perform a scalar query.



来源:https://stackoverflow.com/questions/839739/with-cdatabase-can-i-send-sql-without-using-crecordset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!