我试图在多个表中保存记录我使用的是insert语句但是它给了我“INSERT INTO语句中的语法错误” 这是我的代码
strSQL = " INSERT INTO [2011 Nurse Patient Index]
(File Number, Patient name ,Gender , AgeRTU , Nationality ,
Diagnosis , Other , Appointment , Date)
VALUES('" & File_NumberRTU.Value & "','" & Patient_nameRTU.Value & "' ,
'" & GenderRTU.Value & "', '" & AgeRTU.Value & "' ,
'" & NationalityRTU.Value & "' , '" & DiagnosisRTU.Value & "' ,
'" & OtherRTU.Value & "' , '" & AppointmentRTU.Value & "' ,
'" & DateRTU.Value & "')"
CurrentDb.Execute strSQL
此行中出现错误
CurrentDb.Execute strSQL
谁能告诉我哪里出错了? 谢谢
答案 0 :(得分:3)
如果数据库中的日期列类型为Date
或Datetime
,则可能必须使用#来包围DateRTU.Value
,即
INSERT INTO
[2011 Nurse Patient Index]([File Number], [Patient name], Gender, AgeRTU, Nationality, Diagnosis, Other, Appointment, Date)
VALUES
('" & File_NumberRTU.Value & "',
'" & Patient_nameRTU.Value & "',
'" & GenderRTU.Value & "',
'" & AgeRTU.Value & "',
'" & NationalityRTU.Value & "',
'" & DiagnosisRTU.Value & "',
'" & OtherRTU.Value & "',
'" & AppointmentRTU.Value & "',
'#" & DateRTU.Value & "#')"
答案 1 :(得分:1)
尝试围绕[File Number]
和[Patient name]
的方括号。
strSQL = " INSERT INTO [2011 Nurse Patient Index]([File Number], [Patient name] ,Gender , AgeRTU , Nationality , Diagnosis , Other , Appointment , Date)VALUES('" & File_NumberRTU.Value & "','" & Patient_nameRTU.Value & "' , '" & GenderRTU.Value & "', '" & AgeRTU.Value & "' , '" & NationalityRTU.Value & "' , '" & DiagnosisRTU.Value & "' , '" & OtherRTU.Value & "' , '" & AppointmentRTU.Value & "' , '" & DateRTU.Value & "')"
CurrentDb.Execute strSQL