This is because when I access the database using ADO, the retrieved field value is of the _ variant_t type. When using the field value, type conversion is required. It is easy to convert to int. It takes a lot of time to convert to char. After searching for a long time on the Internet, find the relevant method. The most reprinted function is the varianttocstring (variant var) function. Of course, it is used to convert the cstring type. But after the application is applied, it is converted and the program reports an error. I don't know why.
Finally, I thought of a final solution. Although I did not find the root cause of the error, I successfully prevented the error from "appearing in front of you ". In fact, it is also very simple, just using try catch
_ Variant_t GPRS Sid;
Gprs sid = "1234567890"; // The value returned by the database processing function, that is, the value of the _ variant_t type.
Const char * GPRS Sid;
Try
{
_ Bstr_t bst_t = uplsid;
Gprs sid = (const char *) bst_t;
}
Catch (...)
{
// Printf ("% s \ r \ n", uplsid );
// The purpose of the above sentence is to test that the conversion of the GPRS Sid has been successful, but an error occurred in the middle. The comment has no effect on the program below, so the error is hidden, but the type conversion is successful, and the goal has been achieved.
}
// Continue to execute other code.
Comment: In fact, not only in C ++, but in other languages, such as C #, it must have been applied in the same industry. I call this method "Seeking for perfection!