CString strTmp;
for(int i = 1 ; i < 10 ; i++)
{
strTmp.Format("00%d",i);
m_pSet->m_strFilter = "ID = '" + strTmp + "'";
m_pSet->Requery();
}
查询ID为001到009的数据。如果数据库中没有007(不确定的ID,也可能是006)的记录就会出错:超出数据范围。如果要加一个处理过程,当找不到007的时候程序继续找下一个ID,怎么做?
我没有接触过异常处理,大家说的时候尽量详细点,我用的时ODBC+Access
for(int i = 1 ; i < 10 ; i++)
{
strTmp.Format("00%d",i);
m_pSet->m_strFilter = "ID = '" + strTmp + "'";
m_pSet->Requery();
}
查询ID为001到009的数据。如果数据库中没有007(不确定的ID,也可能是006)的记录就会出错:超出数据范围。如果要加一个处理过程,当找不到007的时候程序继续找下一个ID,怎么做?
我没有接触过异常处理,大家说的时候尽量详细点,我用的时ODBC+Access
...
strTmp.Format("00%d",i);
m_pSet->m_strFilter = "ID = '" + strTmp + "'";
m_pSet->Requery(); if( ! m_pSet->IsEof() )
{
...
}
}
异常原来不在m_pSet->Requery(),而是我接下来用的
m_pSet->MoveFirst()。
用
try
{
m_pSet->MoveFirst()
}
.....
就可以