不是用SQL语句,而是在打开的数据库中查询的,类似C++Builder中的Locate方法。
解决方案 »
- 服务器send()但始终返回-1,客户端接收不到FD_READ事件?
- 怎么复制数据
- 客户端连接出现10061,ping服务器地址也不通,怎么处理?
- CSDN 开始玩浮动广告了
- 请问这个操作“内存中的位图->位图文件->硬盘”
- 【一直没有解决的老问题】OnLButtonDown中得到的点的座标要转换为在 整个ScrollView中的座标
- 动态create控件问题
- ATL速成论?
- 初始化问题,别见笑啊!!
- 如何在MDI视图中实现标尺Ruler
- 电子地图-mapinfo
- 如何终止正在连接中和正在下栽中的线程,我用的是CHttpConnection和CHttpFile(不能强制退出,因为有许多资源要释放)
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")#include <ole2.h>
#include <stdio.h>
#include <conio.h>
#include "FindX.h"// Function declarations
inline void TESTHR(HRESULT x) {if FAILED(x) _com_issue_error(x);};
void FindX(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);//////////////////////////////////////////////////////////
// //
// Main Function //
// //
//////////////////////////////////////////////////////////void main()
{
if(FAILED(::CoInitialize(NULL)))
return; FindX(); //Wait here for the user to see the output.
printf("Press any key to continue...");
getch();
::CoUninitialize();
}//////////////////////////////////////////////////////////
// //
// FindX Function //
// //
//////////////////////////////////////////////////////////void FindX(void)
{
HRESULT hr = S_OK; // Define ADO object pointers.
// Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstTitles = NULL;
IADORecordBinding *picRs = NULL; //Interface Pointer declared.
CTitlesRs titlers; //C++ class object _bstr_t strCnn("Provider=sqloledb;Data Source=MyServer;"
"Initial Catalog=pubs;Integrated Security=SSPI;"); try
{
// Open connection.
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open (strCnn, "", "", adConnectUnspecified); // Open title Table
TESTHR(pRstTitles.CreateInstance(__uuidof(Recordset)));
pRstTitles->Open("SELECT title_id FROM titles",
_variant_t((IDispatch *)pConnection),
adOpenStatic, adLockReadOnly, adCmdText); // The default parameters are sufficient to search forward
// through a Recordset. pRstTitles->Find ("title_id LIKE 'BU%'",0,adSearchForward,""); //Open an IADORecordBinding interface pointer which
//we'll use for Binding Recordset to a class
TESTHR(pRstTitles->QueryInterface(
__uuidof(IADORecordBinding),(LPVOID*)&picRs)); //Bind the Recordset to a C++ Class here
TESTHR(picRs->BindToRecordset(&titlers)); // Skip the current record to avoid finding the same
// row repeatedly. The book is redundant because Find
// searches from the current position.
int count = 0; //Continue if last find succeeded.
while (!(pRstTitles->EndOfFile))
{
printf("Title ID: %s\n",titlers.lt_titleidStatus == adFldOK ?
titlers.m_szt_titleid : "<NULL>");
count++; //Count the last title found. _variant_t = pRstTitles->Book; //Note current pos.
pRstTitles->Find("title_id LIKE 'BU%'", 1, adSearchForward,
);
} //Release IADORecordset Interface
if (picRs)
picRs->Release(); // Clean up objects before exit.
pRstTitles->Close();
pConnection->Close();
printf("The number of business titles is %d\n",count); }
{
// Notify the user of errors if any.
// Pass a connection pointer accessed from the Recordset.
PrintProviderError(pConnection);
PrintComError(e);
}
}//////////////////////////////////////////////////////////
// //
// PrintProviderError Function //
// //
//////////////////////////////////////////////////////////void PrintProviderError(_ConnectionPtr pConnection)
{
// Print Provider Errors from Connection object.
// pErr is a record object in the Connection's Error collection.
ErrorPtr pErr = NULL; if( (pConnection->Errors->Count) > 0)
{
long nCount = pConnection->Errors->Count;
// Collection ranges from 0 to nCount -1.
for(long i = 0; i < nCount; i++)
{
pErr = pConnection->Errors->GetItem(i);
printf("\t Error number: %x\t%s", pErr->Number,
(LPCSTR)pErr->Description);
}
}
}//////////////////////////////////////////////////////////
// //
// PrintComError Function //
// //
//////////////////////////////////////////////////////////void PrintComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description()); // Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
// EndFindCppFindX.h// BeginFindH
#include "icrsint.h"//This Class extracts only titleId from Titles table.
class CTitlesRs : public CADORecordBinding
{
BEGIN_ADO_BINDING(CTitlesRs) // Column title_id is the 1st field in the recordset
// from Titles table.
ADO_VARIABLE_LENGTH_ENTRY2(1, adVarChar, m_szt_titleid,
sizeof(m_szt_titleid), lt_titleidStatus, FALSE)END_ADO_BINDING()public:
CHAR m_szt_titleid[150];
ULONG lt_titleidStatus;
};
// EndFindH