CDatabase::ExecuteSQL()

来源:互联网 发布:上海银行淘宝金卡年费 编辑:程序博客网 时间:2024/05/10 15:13

CDatabase::ExecuteSQL

Call this member function whenyou need to execute a SQL command directly.

当你要直接执行SQL命令的时候就访问这个成员函数

void ExecuteSQL(

  LPCTSTR lpszSQL 

);


lpszSQL

Pointer to anull-terminated string containing a valid SQL command to execute. You can passaCString.

一个指向以null结尾的string指针,string字符串包含一个可执行SQL命令。你可以直接传递一个Cstring

Remarks


Create the commandas a null-terminated string.ExecuteSQL does not return data records. Ifyou want to operate on records, use a recordset object instead.

将命令创建长null-terminated结尾的string。函数不返回数据集。如果你想操作数据集,请改用recordset对象。

Most of yourcommands for a data source are issued through recordset objects, which supportcommands for selecting data, inserting new records, deleting records, andediting records. However, not all ODBC functionality is directly supported bythe database classes, so you may at times need to make a direct SQL call withExecuteSQL.

大多数关于数据源的命令是通过recordset对象发布的,它支持选择数据源,插入新的记录,删除记录以及编辑记录。然而,并不是所有的ODBC功能都被database类直接支持,所以有时候你需要用ExecuteSQL成员函数来直接访问SQL。

Example


try

  {

     m_dbCust.ExecuteSQL(

        _T("UPDATE Taxes")

           _T("SET Rate ='36' ")

           _T("WHERE Name= 'Federal'"));

  }

  catch(CDBException* pe)

  {

     // The error code isin pe->m_nRetCode

 

     pe->ReportError();

     pe->Delete();

  }

 

 

try

{

  m_dbCust.ExecuteSQL(

     _T("UPDATE Taxes ")

        _T("SET Rate = '36' ")

         _T("WHERE Name = 'Federal'"));

}

catch(CDBException* pe)

{

   //The error code is in pe->m_nRetCode

  pe->ReportError();

  pe->Delete();

}

 

Requirements


Header: afxdb.h

 

0 0
原创粉丝点击