CDatabase::ExecuteSQL void ExecuteSQL( LPCSTR lpszSQL ); throw( CDBException );ParameterslpszSQLPointer to a null-terminated string containing a valid SQL command to execute. You can pass a CString.ResCall this member function when you need to execute an SQL command directly. Create the command as a null-terminated string. 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.ExampleCString strCmd = "UPDATE Taxes SET Federal = 36%";TRY { m_dbCust.ExecuteSQL( strCmd ); }CATCH(CDBException, e) { // The error code is in e->m_nRetCode }END_CATCH
void ExecuteSQL( LPCSTR lpszSQL );
throw( CDBException );ParameterslpszSQLPointer to a null-terminated string containing a valid SQL command to execute. You can pass a CString.ResCall this member function when you need to execute an SQL command directly. Create the command as a null-terminated string. 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.ExampleCString strCmd = "UPDATE Taxes SET Federal = 36%";TRY
{
m_dbCust.ExecuteSQL( strCmd );
}CATCH(CDBException, e)
{
// The error code is in e->m_nRetCode
}END_CATCH
CString SQL=sql语句
pDaoDatabase->Execute(SQL)
sql=create table.......
hr=m_pCon->Execute(_bstr_t(sql),&v,adCmdText);
CDatabase m_local;//定义本地数据库
CTime sysdate,cssj;
CString strcmd,lh_temp;
lh_temp = "yangbit test!";
strcmd.Format(_T("insert into test(cssj,lh) values (sysdate,'%s')"),lh_temp);
m_local.OpenEx( _T("DSN=local;UID=xg_dba;PWD=gb2001"),CDatabase::noOdbcDialog );
m_local.ExecuteSQL(strcmd);
m_local.Close();这是一部分,插入表test中cssj,lh两个列中当前时间和字符串,数据库Oracle,sysdate在Oracle中是系统时间。
如果要直接插入字符串就用
strcmd.Format(_T("insert into test(cssj,lh) values (sysdate,'yangbit test!')"));