我是想把一个数据表(RecordSet)中具有条件
if(var.pbVal==strName)
的数据复制到另外一个具有相同结构的数据表(addRS)中,
在调试过程中出现这样的问题:
1.语句从while开始执行,第一次执行断点位置时候
即:RecordSet.GetFieldValue("日期",var);
没有任何问题
2.第二次执行断点位置时候出现图中弹出的对话框
请问这是什么原因?
if(var.pbVal==strName)
的数据复制到另外一个具有相同结构的数据表(addRS)中,
在调试过程中出现这样的问题:
1.语句从while开始执行,第一次执行断点位置时候
即:RecordSet.GetFieldValue("日期",var);
没有任何问题
2.第二次执行断点位置时候出现图中弹出的对话框
请问这是什么原因?
if(::strcmp(var.pbVal, strName) == 0)
pbVal是unsigned char *型,直接用 == 是指针的比较,另外使用时注意分配内存
如果strName为CString 类型的对象,还可以使用CString 类的Compare成员函数,如下:
CString s1( "abc" );
CString s2( "abd" );
ASSERT( s1.Compare( s2 ) == -1 ); // Compare with another CString.
ASSERT( s1.Compare( _T("abe" ) ) == -1 ); // Compare with LPTSTR string.
COleVariant var;
while(!RecordSet.IsBOF())
{
RecordSet.GetFieldValue("日期",var); //出错行
if(var.pbVal<strName)
break;
else if(var.pbVal==strName)
{
addRS.AddNew();
for(i=0;i<count;i++)
{
RecordSet.GetFieldValue(i,var);
addRS.SetFieldValue(i,var);
}
addRS.Update();
}
RecordSet.MoveNext();
}
出错信息:
Unhandlede exception in Second.exe(KERNEL32.DLL):0xE06D7363:Microsoft C++ Exception.另外还有一个相关的问题,如下:
COleVariant var;
RecordSet.Edit();
var.intVal=20;
RecordSet.SetFieldValue("上行衰减值",var); //出错行
...
RecordSet.Update();出错信息:
Unhandlede exception in Second.exe(OLEAUT32.DLL):0xC0000005:Access Violation.