簡體   English   中英

SQl中的INSERT語句

[英]INSERT statement in SQl

我正在嘗試將記錄保存到一個以上的表中,而我正在使用插入語句,但是它給了我“ 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

誰能告訴我我哪里出問題了? 謝謝

如果數據庫中的“日期”列的類型為“ 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 & "#')"

嘗試在[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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM