From b90b852560c33cb67945ecb40c7316271b7dd0d6 Mon Sep 17 00:00:00 2001 From: zyx <1029606625@qq.com> Date: Thu, 7 Jul 2022 16:21:37 +0800 Subject: [PATCH] =?UTF-8?q?2022-06-07=2016:20=201=E3=80=81executeSql?= =?UTF-8?q?=E6=9B=B4=E6=94=B9adBSTR=E4=B8=BAadVarChar=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=80=BC=E5=AE=BD=E5=BA=A6=E9=97=AE=E9=A2=98=202?= =?UTF-8?q?=E3=80=81=E5=AF=BC=E5=85=A5=E6=96=87=E4=BB=B6=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=98=E5=9C=A8=E6=A3=80=E6=B5=8B=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E4=BA=A7=E7=94=9F=E4=B8=BB=E9=94=AE=E9=87=8D?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseDAOImpl.cpp | 2 +- Menu.cpp | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/BaseDAOImpl.cpp b/BaseDAOImpl.cpp index 14209b4..eda4371 100644 --- a/BaseDAOImpl.cpp +++ b/BaseDAOImpl.cpp @@ -15,7 +15,7 @@ _RecordsetPtr executeSql(_ConnectionPtr connection, const char* sql, vectorsize(); for (size_t i = 0; i < size; i++) { - _ParameterPtr p = command->CreateParameter("var" + i, adBSTR, adParamInput, sizeof((*v)[i].c_str()), (*v)[i].c_str()); + _ParameterPtr p = command->CreateParameter("var" + i, adVarChar, adParamInput, sizeof((*v)[i]), (*v)[i].c_str()); command->Parameters->Append(p); } return command->Execute(NULL, NULL, long(0)); diff --git a/Menu.cpp b/Menu.cpp index e7b8ef3..eeae22f 100644 --- a/Menu.cpp +++ b/Menu.cpp @@ -861,12 +861,14 @@ void importStudentData(_ConnectionPtr connection) { Student* student = new Student(); while (!inFile.eof()) { inFile >> title[0] >> title[1] >> title[2] >> title[3] >> title[4]; - student->setId(title[0]); - student->setName(title[1]); - student->setSex(title[2]); - student->setStuClass(title[3]); - student->setStatus(title[4]); - addStudent(connection, *student); + if (getStudentById(connection, title[0]) == NULL) { + student->setId(title[0]); + student->setName(title[1]); + student->setSex(title[2]); + student->setStuClass(title[3]); + student->setStatus(title[4]); + addStudent(connection, *student); + } } printf("成功导入student.txt文件!\n"); inFile.close(); @@ -889,9 +891,11 @@ void importCourseData(_ConnectionPtr connection) { Course* course = new Course(); while (!inFile.eof()) { inFile >> title[0] >> title[1]; - course->setId(title[0]); - course->setName(title[1]); - addCourse(connection, *course); + if (getCourseById(connection, title[0]) == NULL) { + course->setId(title[0]); + course->setName(title[1]); + addCourse(connection, *course); + } } printf("成功导入course.txt文件!\n"); inFile.close(); @@ -914,10 +918,12 @@ void importGradeData(_ConnectionPtr connection) { Grade* grade = new Grade(); while (!inFile.eof()) { inFile >> title[0] >> title[1] >> title[2]; - grade->setStuId(title[0]); - grade->setCourseId(title[1]); - grade->setGrade(title[2]); - addGrade(connection, *grade); + if (getOnesGrade(connection, title[0], title[1]) == NULL) { + grade->setStuId(title[0]); + grade->setCourseId(title[1]); + grade->setGrade(title[2]); + addGrade(connection, *grade); + } } printf("成功导入grade.txt文件!\n"); inFile.close();