通过ADO访问Oracle数据库中的一个数据表,程序如下:
int COHDCXDlg::Search()
{
CoInitialize(NULL);
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSql;
strSql.Format("select * from position_table where position_table.car_name=%s and position_table.position_name=%s",m_shiptype,m_scheme);
BSTR bstrSQL=strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
......
}
m_pRecordset->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
CoUninitialize();
return bujuID;
}
m_shiptype,m_scheme为两个文本控件关联变量,position_table为数据表
单步调试时,总是运行到strSql.Format("...")语句时就弹出“IDispatch error #3092”
的错误提示,并自动退出程序了.向高人求解?
int COHDCXDlg::Search()
{
CoInitialize(NULL);
try
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
CString strSql;
strSql.Format("select * from position_table where position_table.car_name=%s and position_table.position_name=%s",m_shiptype,m_scheme);
BSTR bstrSQL=strSql.AllocSysString();
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
......
}
m_pRecordset->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.ErrorMessage());
}
CoUninitialize();
return bujuID;
}
m_shiptype,m_scheme为两个文本控件关联变量,position_table为数据表
单步调试时,总是运行到strSql.Format("...")语句时就弹出“IDispatch error #3092”
的错误提示,并自动退出程序了.向高人求解?
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);
开始执行后弹出那个消息对话框。
不知道哪个是异常:
Loaded 'ntdll.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\system32\MFC42D.DLL'
Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
Loaded 'C:\WINDOWS\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\user32.dll', no matching symbolic information found.
Loaded symbols for 'C:\WINDOWS\system32\MFCO42D.DLL'
Loaded 'C:\WINDOWS\system32\ole32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\oleaut32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mfc42loc.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\MSCTF.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\clbcatq.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comres.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
Loaded 'C:\Documents and Settings\Administrator\桌面\cwui.ocx', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mfc42.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shell32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\shlwapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\olepro32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcp60.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msimg32.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\System\ado\msado15.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msdart.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comdlg32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\xpsp2res.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\System\Ole DB\oledb32.dll', no matching symbolic information found.
Loaded 'C:\Program Files\Common Files\System\Ole DB\oledb32r.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDB.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oci.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDBgmr.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDBrst.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\ORANLS8.DLL', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oracore8.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDButl.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDBzhs.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\OraOLEDBpus.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswstr10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswdat10.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\comsvcs.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\colbact.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mtxclu.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wsock32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2_32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\ws2help.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\netapi32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\clusapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\resutils.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\userenv.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oraclient8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oravsn8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oracommon8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orageneric8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranl8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oran8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orancrypt8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranro8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orannzsbb8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranldap8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oraldapclnt8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranhost8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranoname8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\ORANCDS8.DLL', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orantns8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orannds8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranms.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oranmsp.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\oratrace8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\ORAPLS8.DLL', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\ORASLAX8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orawtc8.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\ORASQL8.DLL', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orantcp8.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\dnsapi.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winrnr.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\rasadhlp.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\hnetcfg.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
Loaded 'D:\oracle\ora81\bin\orannts8.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\security.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msapsspc.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt40.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\schannel.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\digest.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msnsspc.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msvcrt40.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\msv1_0.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\iphlpapi.dll', no matching symbolic information found.
Loaded 'D:\Program Files\Microsoft Visual Studio\MyProjects\OHDCX\mesa.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\mscms.dll', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\winspool.drv', no matching symbolic information found.
Loaded 'C:\WINDOWS\system32\icm32.dll', no matching symbolic information found.
First-chance exception in OHDCX.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
The thread 0xC68 has exited with code 2 (0x2).
The thread 0xECC has exited with code 2 (0x2).
The thread 0x8D4 has exited with code 2 (0x2).
The thread 0xB28 has exited with code 2 (0x2).
The program 'D:\Program Files\Microsoft Visual Studio\MyProjects\OHDCX\Debug\OHDCX.exe' has exited with code 2 (0x2).
然后,在放到SQL查询工具内进行验证,这样会更能调试出错误所在。希望楼主成功!努力!
m_pRs->PutRefActiveConnection(m_pConn);
m_pRs->Open("select * from table", _variant_t((IDispatch*)m_pConn, true), adOpenDynamic,adLockOptimistic, adCmdUnknown);
另外,我在文本框中输入的m_shiptype或m_scheme在数据表中不存在时,程序老是执行到
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenStatic,adLockOptimistic,adCmdText);这里就结束了?
请问:如果要提示用户数据表中不存在所输入的文本项,怎样实现,或怎样写这个判断的sQL语句?
if (m_pRecordset->rsEOF)
{
//不存在所输入的文本项
}