我应该明白是怎么回事了,我在设置后的代码里加了判断的代码,发现确实这个属性是不能修改的, hr = pICommandProperties->SetProperties(1, dbpropset); if (FAILED(hr)) { if (DBPROPSTATUS_NOTSETTABLE == dbpropset[0].rgProperties->dwStatus) { AfxMessageBox(_T("The provider does not support setting the property to the requested value")); } return hr; }dwStatus结果确实就是DBPROPSTATUS_NOTSETTABLE ,那就是说,每次读取多少条记录是不可设置的。 我参考的是MSDN上的: For ICommandProperties::SetProperties or IDBProperties::SetProperties, if the provider supports the specified property and SetProperties determines that the provider does not support setting the property to the requested value, it sets dwStatus to DBPROPSTATUS_NOTSUPPORTED and returns DB_S_ERRORSOCCURRED if one or more properties passed to SetProperties were successfully set, or DB_E_ERRORSOCCURRED if none of the properties could be set. If the provider supports the specified property but SetProperties cannot determine whether the provider supports the requested value, it sets dwStatus to DBPROPSTATUS_OK. When ICommand::Execute or IDBInitialize::Initialize is called, the provider determines whether it can support the requested value. If the provider cannot support the requested value, ICommand::Execute or IDBInitialize::Initialize returns DB_E_ERRORSOCCURRED. 不过MSDN上有另一个地方写的感觉和上面的有些不一致,我感觉是有点矛盾: DBPROP_MAXOPENROWS Property group: RowsetProperty set: DBPROPSET_ROWSETColumn? NType: VT_I4Typical R/W: R/WDescription: Maximum Open Rows 这里写的是R/W,应该是可读可写的意思,但是应该是不可设置的,那应该就是不可写了,我感觉是这个意思,大家看看是不是这个意思,我没理解错吧
cRows 是传入参数啊,表示你要取多少条。传入1取得一条没错啊!
如果不设置,默认是一次只能取一条记录,我想设置成一次可以取多条记录,但是设置不成功,pICommandProperties->SetProperties总是返回失败
另外,要改的话,怎么才能改成客户端游标?
if (FAILED(hr))
{
if (DBPROPSTATUS_NOTSETTABLE == dbpropset[0].rgProperties->dwStatus)
{
AfxMessageBox(_T("The provider does not support setting the property to the requested value"));
}
return hr;
}dwStatus结果确实就是DBPROPSTATUS_NOTSETTABLE ,那就是说,每次读取多少条记录是不可设置的。
我参考的是MSDN上的:
For ICommandProperties::SetProperties or IDBProperties::SetProperties, if the provider supports the specified property and SetProperties determines that the provider does not support setting the property to the requested value, it sets dwStatus to DBPROPSTATUS_NOTSUPPORTED and returns DB_S_ERRORSOCCURRED if one or more properties passed to SetProperties were successfully set, or DB_E_ERRORSOCCURRED if none of the properties could be set. If the provider supports the specified property but SetProperties cannot determine whether the provider supports the requested value, it sets dwStatus to DBPROPSTATUS_OK. When ICommand::Execute or IDBInitialize::Initialize is called, the provider determines whether it can support the requested value. If the provider cannot support the requested value, ICommand::Execute or IDBInitialize::Initialize returns DB_E_ERRORSOCCURRED.
不过MSDN上有另一个地方写的感觉和上面的有些不一致,我感觉是有点矛盾:
DBPROP_MAXOPENROWS Property group: RowsetProperty set: DBPROPSET_ROWSETColumn? NType: VT_I4Typical R/W: R/WDescription: Maximum Open Rows 这里写的是R/W,应该是可读可写的意思,但是应该是不可设置的,那应该就是不可写了,我感觉是这个意思,大家看看是不是这个意思,我没理解错吧
不会你的数据只有一条?
我刚试着把游标设置成客户端游标,但是dwStatus是1,即DBPROPSTATUS_NOTSUPPORTED,说明不支持客户端游标。
并不是整体取记录比一条条取慢。反而是服务端游标可以在取了少量记录后就有界面相应。
两者在单纯用在取数上的时间没有明显的差异。你可以用查询分析器执行一下SQL,先把查询慢的可能排除掉。
通常是初始进行连接会比较花时间,这个时间要排除;然后界面输出也比较花时间,也排除掉。单纯取数慢不慢。
一个纯粹遍历一遍数据库中所有数据的函数TestTime,花了2443ms,数据库中有18000条数据,TestTime函数中取数据的循环,花了2216ms,也就是说,大部分的时间是花在取数据上了,我也不知道这是算快还是算慢
一个纯粹遍历一遍数据库中所有数据的函数TestTime,花了2443ms,数据库中有18000条数据,TestTime函数中取数据的循环,花了2216ms,也就是说,大部分的时间是花在取数据上了,我也不知道这是算快还是算慢
感觉还是别的代码花的时间长了一些
全取1万8是非常不合理的。