When the field value of the database is allowed to be empty, and the content is also empty at this time, execution of the query will cause an error, such as
CString str = precordset->getfields ()->getitem ((long) 0)->getvalue ();
Or
str=precordset->getcollect ("Posinfo");
Will pop up the following window prompt error!
even more strange is the catch (...) And I can't catch the exception .
I got a big head on a problem today and finally got it.
Cause of error: After GETCOLLCT returned null because STR is a CString object compiler automatically converts _varint_t to CString and _varint_t is empty so the conversion failed is not a database exception and is not an exception at all. catch (...) Unable to seize.
Solution Solutions
In a potentially empty place, add the following code
_variant_t var; Var= m_precordset->getcollect ("Posinfo"); May be empty if (var.vt! = vt_null) //Is null { strposinfo = var; } else { strposinfo = "";}
You'll be able to detect null values.