( db.Execute "insert into Studentstemp(StudentNameA,FacultyNumber,DepartmentNumber" & _
",BatchDescription,programNumber, Studentstatus, Gender, AddmissionFormNo, StudentNumber)values('" & VBA.Trim(TxtStudentNameA.Text) & "','" & _
CmbFaculty.BoundText & "','" & _
CmbDepartMent.BoundText & "','" & _
CmbBatch.BoundText & "','" & _
CmbProgram.BoundText & "','" & _
Cmbastatute.Text & "','" & _
CmbGnder.Text & "','" & _
TxtStudyFees.Text & ")")
答案 0 :(得分:2)
(db.Execute "insert into Studentstemp(StudentNameA,FacultyNumber,DepartmentNumber" & _
",BatchDescription,programNumber, Studentstatus, Gender, AddmissionFormNo" & _
",StudentNumber)values('" & VBA.Trim(TxtStudentNameA.Text) & "','" & _
CmbFaculty.BoundText & "','" & CmbDepartMent.BoundText & "','" & _
CmbBatch.BoundText & "','" & CmbProgram.BoundText & "','" & _
Cmbastatute.Text & "','" & CmbGnder.Text & "','" & TxtStudyFees.Text & "')")
答案 1 :(得分:1)
高级拱门告诉你的是,如果程序中输入的其中一个字符串中包含撇号,则会出现此错误。要自己证明这一点,请在txtStudentName中输入学生姓名“O'Malley”。现在,我同意你应该使用参数,但要解决这个特殊问题,你需要这样做:
...values('" & _
Replace(Trim(txtStudentName.Text), "'", "''") & "','" & _
Replace(CmbFaculty.BoundText, "'", "''") & "','" & _
Replace(CmbDepartMent.BoundText, "'", "''") & "','" & _
...
等等。 SQL需要两个撇号来表示文字撇号,因此'O''Malley'
将是在SQL中的字段中输入值O'Malley的方法。