我确定代码是正确的。我在C ++ / CLI环境中从database.h执行调用方法 在执行期间,执行 SQL select语句的行遇到System.Runtime.InteropServices.SEHException,外部组件抛出了异常。
这是C ++环境 database.h
int SQLconn::displayData(string model) {
int count;
if (con == NULL) {
cout << "Please setup connection first!";
system("Pause");
}else {
stmt = con->createStatement();
res = stmt->executeQuery("SELECT Model, COUNT(*) FROM database WHERE Model = '" + model + "'");
while (res->next()) {
count = res->getInt("COUNT(*)");
int total = Convert::ToInt32(count);
return total;
}
}
};
这是C ++ / CLI环境
SQLConn sqlConn;
int sam = sqlConn.displayData("Broom");
String^ SamCount = sam.ToString();
this->chart2->Series["occurenceCount"]->Points->AddXY("Broom", SamCount);