我用ADO的方式从数据中读数据,但是每次总是读出那张表的一部分记录,同样的SQL语句在Sql plus中可以读出所有的记录,不明白是怎么一回事情?下面是我写的代码,请高手帮忙。在数据中是有Tserver1这条记录的,用SQL plus也能查的到,但是用程序不能读出来。
BOOL CCTIAppView::ReadDataBase(void)
{
//COM组件初始化
::CoInitialize(NULL); _ConnectionPtr pConnection;
_RecordsetPtr pRecordset; try
{
pConnection.CreateInstance(__uuidof(Connection));
CString strSql;
strSql.Format("select * from initparameter");
m_strConn.TrimRight(' ');
pConnection->Open(m_strConn.AllocSysString(),"","",-1); pRecordset.CreateInstance(__uuidof(Recordset));
BSTR bstrSQL = strSql.AllocSysString();
pRecordset->CursorLocation = adUseClient;
pRecordset->Open(bstrSQL,_variant_t((IDispatch*)pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); if(!(pRecordset->BOF && pRecordset->adoEOF))
{
while(!pRecordset->adoEOF)
{
_variant_t vItem;
vItem = pRecordset->GetCollect("PARAITEM"); _variant_t vValue;
vValue = pRecordset->GetCollect("PARAVALUE"); if(vItem.vt != VT_NULL)
{
CString Item;
Item = (char*)_bstr_t(vItem);
Item.TrimRight(' '); CString Value;
Value = (char*)_bstr_t(vValue);
Value.TrimRight(' '); CString sItem;
sItem.Format("Tserver%d", 1);
sItem.TrimRight(' '); if(Item.CompareNoCase(sItem) == 0)
{
AfxMessageBox(Value);
}
} pRecordset->MoveNext();
}
}
pRecordset->Close();
pConnection->Close(); }
catch(_com_error e)
{
CString pStr;
try
{
if(pRecordset != NULL)
pRecordset->Close();
if(pConnection != NULL)
pConnection->Close();
}
catch(_com_error e)
{
pStr = "数据库操作异常,请检查计算机网络连接!";
pStr +=e.ErrorMessage(); ::MessageBox(NULL,pStr,"CTI告警!",MB_OK|MB_ICONSTOP);
} ::CoUninitialize(); return FALSE;
}
catch(...)
{
::MessageBox(NULL ,"请检查数据库连接!","告警",MB_OK|MB_ICONSTOP); ::CoUninitialize(); return FALSE;
} ::CoUninitialize(); return TRUE;
}
BOOL CCTIAppView::ReadDataBase(void)
{
//COM组件初始化
::CoInitialize(NULL); _ConnectionPtr pConnection;
_RecordsetPtr pRecordset; try
{
pConnection.CreateInstance(__uuidof(Connection));
CString strSql;
strSql.Format("select * from initparameter");
m_strConn.TrimRight(' ');
pConnection->Open(m_strConn.AllocSysString(),"","",-1); pRecordset.CreateInstance(__uuidof(Recordset));
BSTR bstrSQL = strSql.AllocSysString();
pRecordset->CursorLocation = adUseClient;
pRecordset->Open(bstrSQL,_variant_t((IDispatch*)pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); if(!(pRecordset->BOF && pRecordset->adoEOF))
{
while(!pRecordset->adoEOF)
{
_variant_t vItem;
vItem = pRecordset->GetCollect("PARAITEM"); _variant_t vValue;
vValue = pRecordset->GetCollect("PARAVALUE"); if(vItem.vt != VT_NULL)
{
CString Item;
Item = (char*)_bstr_t(vItem);
Item.TrimRight(' '); CString Value;
Value = (char*)_bstr_t(vValue);
Value.TrimRight(' '); CString sItem;
sItem.Format("Tserver%d", 1);
sItem.TrimRight(' '); if(Item.CompareNoCase(sItem) == 0)
{
AfxMessageBox(Value);
}
} pRecordset->MoveNext();
}
}
pRecordset->Close();
pConnection->Close(); }
catch(_com_error e)
{
CString pStr;
try
{
if(pRecordset != NULL)
pRecordset->Close();
if(pConnection != NULL)
pConnection->Close();
}
catch(_com_error e)
{
pStr = "数据库操作异常,请检查计算机网络连接!";
pStr +=e.ErrorMessage(); ::MessageBox(NULL,pStr,"CTI告警!",MB_OK|MB_ICONSTOP);
} ::CoUninitialize(); return FALSE;
}
catch(...)
{
::MessageBox(NULL ,"请检查数据库连接!","告警",MB_OK|MB_ICONSTOP); ::CoUninitialize(); return FALSE;
} ::CoUninitialize(); return TRUE;
}
解决方案 »
- tcp/ip相关的几个问题?
- 如何判断局域网上某台电脑某个盘上的文件是否存在?
- 我用CInternetSession写的下载控件,在同一网段的局域网内运行正常,可在公网上就不行了?
- _beginthreadex 引起的资源泄露
- 小弟新人 有个问题想求解
- 50分,请问用什么方法可以复制正在被别的程序使用的文件?
- 如何在VC中导入CorelDraw画的图形?
- 有一条警告信息,请问这是什么什么错误呀?
- 在vc 中,如何从注册表里提取网卡号,最好给一些例子,小妹谢了:)
- 请问使用SDK编程时,如何获得设备句柄
- 这个SQL语句该怎么写?
- 一些例程的DIALOG在RESOURCE 下无法看到其DIALOG ,这种情况是如何调整界面的
而且也不见得的没读完, recordset 会 把结果分页 比如说 100条结果记录, 你设置页记录数为 30 它就会读成 4页 30,30,30,10