Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 运行时错误3134 Microsoft Access_Sql_Ms Access - Fatal编程技术网

Sql 运行时错误3134 Microsoft Access

Sql 运行时错误3134 Microsoft Access,sql,ms-access,Sql,Ms Access,我无法确定错误问题的根本原因 下面是我的SQL语句 CurrentDb.Execute "INSERT INTO Kids(ID,First,Last,Age,Gender,Race,Org,School,Address,City,State,Zip,Name_of_Parent_Guardian,Parent_Guardian_Phone,Parent_Guardian_Email_Address,Child_s_Phone,Child_s_Email_Address,Siblings_Who

我无法确定错误问题的根本原因

下面是我的SQL语句

CurrentDb.Execute "INSERT INTO Kids(ID,First,Last,Age,Gender,Race,Org,School,Address,City,State,Zip,Name_of_Parent_Guardian,Parent_Guardian_Phone,Parent_Guardian_Email_Address,Child_s_Phone,Child_s_Email_Address,Siblings_Who_Participated_in_KIF,Years_Participated_in_KIF,On_Facebook_Y_or_N,On_Pic_Pals_Y_or_N,Notes_Comments,Year" & _
"Value ('" & "','" & Me.First.Value & "','" & Me.Last.Value & "','" & Me.Age.Value & "','" & Me.Gender.Value & "','" & Me.Race.Value & "','" & Me.Org.Value & "','" & Me.School.Value & "','" & Me.Address.Value & "','" & Me.City.Value & "','" & Me.State.Value & "','" & Me.Zip.Value & "','" & Me.NameofparentG.Value & "','" & Me.parentphone.Value & "','" & Me.parentemail.Value & "','" & Me.Child_sphone.Value & "','" & Me.Child_sEmailAddress.Value & "','" & Me.Sibling_s_WhoParticipatedinKIF.Value & "','" & Me.Year_ParticipatedinKIF.Value & "','" & Me.OnFacebook_Y_or_N_.Value & "','" & Me.NotesComments.Value & "','" & Me.Year.Value & "')"
检查你的语法

应该是这样的:

INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);

不能被足够强调:考虑使用一个参数化查询,它避免了一个更可读、可维护、更安全的代码的引用处理和变量连接。Access SQL允许

PARAMETERS
子句指定具有定义类型的命名参数,这些类型可以在VBA中使用调用

SQL(另存为数据库中存储的查询,根据需要调整类型和大小)

参数[IDParam]文本(255),[FirstParam]文本(255),[LastParam]文本(255),[AgeParam]文本(255),[GenderParam]文本(255),
[RaceParam]文本(255),[OrgParam]文本(255),[SchoolParam]文本(255),[AddressParam]文本(255),[CityParam]文本(255),
[StateParam]文本(255),[ZipParam]文本(255),[NameofParentParam]文本(255),[parentphoneParam]文本(255),
[parentemailParam]文本(255),[Child_sphoneParam]文本(255),[Child_sEmailAddressParam]文本(255),
[Sibling_s_WhoParticiatedInkifParam]文本(255),[Year_ParticiatedInkifParam]文本(255),
[OnFacebook_Y_或_N_参数]文本(255),[NotesCommmentsSparam]文本(255),[YearParam]文本(255);
插入孩子([ID]、[First]、[Last]、年龄、性别、种族、组织、学校、地址、城市、州、邮编、,
家长监护人姓名、家长监护人电话、家长监护人电子邮件地址、,
儿童电话、儿童电子邮件地址、参加KIF的兄弟姐妹、,
年参与,在Facebook上,在朋友们上,在注释上,在评论中,[年])
值([IDParam]、[FirstParam]、[LastParam]、[AgeParam]、[GenderParam]、[RaceParam],
[OrgParam]、[SchoolParam]、[AddressParam]、[CityParam]、[StateParam]、[ZipParam],
[NameofParentParam]、[parentphoneParam]、[parentemailParam]、[Child_sphoneParam],
[Child\u sEmailAddressParam],[s\u参与InkifParam的兄弟姐妹],[Year\u参与InkifParam],
[在Facebook上的你或你的参数],[注释SPARAM],[年参数];
VBA(将值动态传递给命名参数,然后执行)

Dim db作为数据库
Dim qdef作为QueryDef
Set db=CurrentDb
Set qdef=db.querydfs(“myQueryName”)
qdef![IDParam]=Me.ID
qdef![第一参数]=我,第一
qdef![最后参数]=我,最后一个
qdef![年龄参数]=我的年龄
qdef![性别参数]=我,性别
qdef![赛车参数]=我,赛车
qdef![OrgParam]=Me.Org
qdef!我,学校
qdef![AddressParam]=我的地址
qdef![CityParam]=Me.City
qdef![StateParam]=Me。[状态]
qdef![ZipParam]=Me.Zip
qdef![NameOfParentParam]=Me.NameofparentG
qdef![parentphoneParam]=Me.parentphone
qdef![parentemailParam]=Me.parentemail
qdef![Child_sphoneParam]=Me.Child_sphone
qdef![Child\u sEmailAddressParam]=Me.Child\u sEmailAddress
qdef![Sibling\u s\u whoParticiatedInkifParam]=Me.Sibling\u s\u whoParticiatedInkif
qdef![Year\u particiatedInkIfParam]=Me.Year\u particiatedInkIf
qdef![OnFacebook\u Y\u或\u N\u Param]=Me.OnFacebook\u Y\u或\u N\u
qdef![NotesCommentsParam]=Me.NotesCommentsParam
qdef![YearParam]=Me.YearParam
qdef.executedbfailonerror
设置qdef=Nothing
Set db=Nothing

我强烈建议将上面解析为的串联值存储在字符串变量中,并打印出该值,而不是上面的乱码。我看到一个开放的(列名称,但没有关闭)开始。也许它就像
…注释(注释,年份)一样简单“
也许不是。。。这就是为什么我更希望看到语句被执行,而不仅仅是代码。打开SQL注入,大家会想。您好,BWS,语法是我在Microsoft access表单中用于visual basic的语法。您必须调用CurrentDb。首先执行,然后继续执行sql insert语句。@dtshack=
“…,Notes\u Comments,YearValue(…”
)与
“…,Notes\u Comments,Year)value(…”
)不同。请检查语法。回答得好,各位!