问题
HOW IT SHOULD WORK: User clicks on a listbox with multitude of IDs. Then, the edit controls are filed with the data from the specified ID (row).
HOW IT WORKS: It crashes at res->getString
case LBN_SELCHANGE:
{
string str;
int index = SendMessage(GetDlgItem(hwnd, IDC_lbList), LB_GETCURSEL, 0, 0);
string sint = boost::lexical_cast<std::string>(index);
string smt="SELECT client, telnr, atnrem, papatn, gedapr
FROM tremreg WHERE id = ";
string query = smt + sint;
res = stmt->executeQuery(query.c_str());
//starts crashing here
str = res->getString("client");
SetDlgItemText(hwnd, IDC_eClient, str.c_str());
str = res->getString("telnr");
SetDlgItemText(hwnd, IDC_eTelNr, str.c_str());
str = res->getString("antrem");
SetDlgItemText(hwnd, IDC_eRemAtn, str.c_str());
str = res->getString("paprem");
SetDlgItemText(hwnd, IDC_ePapAtn, str.c_str());
str = res->getString("gedapr");
SetDlgItemText(hwnd, IDC_eGedApr, str.c_str());
delete res;
delete stmt;
}
break;
CRASH INFO:
Unhandled exception at 0x753C812F in Registracija.exe:
Microsoft C++ exception:sql::InvalidArgumentException at memory location 0x0018F7AC.
Digging around google I found somebody mentioning that VARCHAR type values should be fetched with getBlob
. That did not help at all though, and crashed just the same. getInt works however, and is used in other parts of the program.
QUESTION: What steps should I take to make it work?
回答1:
does the same query run properly if you do it in the database directly? Also, are all the returned fields really Strings? And is it valid to call them by name, rather than by the sequence number? I.e. getString(1), etc.
来源:https://stackoverflow.com/questions/24014069/res-getstring-crashes-the-application