- SQL code
sprintf(sqlstr,"select count(*) into :tmpRecord from %s where acno='%s' and trdt between %s and %s;",tabname,sAcno,sBeginDate,sEndDate);
要将count(*)值赋给变量temRecord,如何实现?
------解决方案--------------------------------------------------------
什么版本?似乎不行吧,用打开记录集的方法吧
select count(*) from ....
打开记录集,取第1个值
------解决方案--------------------------------------------------------
你需要使用ADO或者ODBC来打开recordset取得返回值到你的程序中。
------解决方案--------------------------------------------------------
Value 属性范例 (VC++)
本范例通过显示 Employees 表的字段和属性值来演示 Field 和 Property 对象的 Value 属性。
- C/C++ code
// BeginValueCpp
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
#include <ole2.h>
#include <stdio.h>
#include <conio.h>
// Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void ValueX(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);
//////////////////////////////////////////////////////////
// //
// Main Function //
// //
//////////////////////////////////////////////////////////
void main()
{
if(FAILED(::CoInitialize(NULL)))
return;
ValueX();
::CoUninitialize();
}
//////////////////////////////////////////////////////////
// //
// ValueX Function //
// //
//////////////////////////////////////////////////////////
void ValueX(void)
{
HRESULT hr = S_OK;
// Define string variables.
_bstr_t strCnn("Provider='sqloledb';Data Source='MySqlServer';"
"Initial Catalog='pubs';Integrated Security='SSPI';");
// Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_RecordsetPtr pRstEmployees = NULL;
FieldsPtr pFldLoop = NULL;
PropertiesPtr pPrpLoop = NULL;
_variant_t vtIndex;
vtIndex.vt = VT_I2;
try
{
// Open recordset with data from Employee table.
TESTHR(pRstEmployees.CreateInstance(__uuidof(Recordset)));
pRstEmployees->Open ("employee",strCnn ,
adOpenForwardOnly, adLockReadOnly, adCmdTable);
printf("Field values in rstEmployees\n\n");
// Enumerate the Fields collection of the Employees table.
pFldLoop = pRstEmployees->GetFields();
for (int intFields = 0; intFields < (int)pFldLoop->GetCount(); intFields++)
{
vtIndex.iVal = intFields;
// Because Value is the default property of a