使用自动编号在msAccess中插入查询 [英] Insert query in msAccess with autonumber

查看:103
本文介绍了使用自动编号在msAccess中插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cmd1.CommandText =INSERT INTO LoginTable(ID,GivenName,Gender,EMail,UserName,Password)VALUES(@GivenName,@ Gender,@ email,@ UserName,@ Password);



//所有指定的字段都没有问题

// ID是自动编号栏



/ / error:语法错误

解决方案

替换:

  INSERT   INTO  LoginTable(ID,GivenName,性别,电子邮件,用户名,密码) VALUES  @ GivenName  @ Gender  @ EMail  @ UserName  @ Password 



with:

  INSERT   INTO  LoginTable( GivenName,Gender,EMail,UserName,Password) VALUES  @ GivenName  @ Gender  @ EMail  @ UserName  @ Password 





注意:您应该在 INSERT 语句中省略自动增量字段。





如需了解更多信息,请参阅:

在Access中自动生成数字的字段 [ ^ ]

如何重置Access中的自动编号字段值 [ ^ ]


这是一个非常简单的任务

如果你仔细看过你的查询你有 6个表值和 5个参数所以它总是会给你错误所有你要插入的表格值然后必须与参数匹配假设你要插入3个字段然后你只能添加3个参数



现在看看你的查询你有一个额外的字段 id ,因为你提到你有id作为自动增量所以只需删除那个



,您的新查询将如下所示



 cmd1.CommandText =   INSERT INTO LoginTable(GivenName,Gender,EMail,UserName,Password)VALUES(@GivenName,@ Gender,@ email,@ UserName,@密码); 







:)


< blockquote>你可以有一个厕所k在以下链接给出的示例中:

语法错误上嵌件成 - 单柱自动递增表 [<一个HREF =http://social.msdn.microsoft.com/Forums/windows/en-US/13c21f7f-ec5b-4e2a-84da-dd2e3b7adb34/syntax-error-on-insert-into-single-column-auto-increment -tabletarget =_ blanktitle =New Window> ^ ]


cmd1.CommandText = "INSERT INTO LoginTable(ID,GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)";

//all the specified field had no problem
//ID is an autonumber column

//error:syntax error

解决方案

Replace:

INSERT INTO LoginTable(ID,GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)


with:

INSERT INTO LoginTable(GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)



Note: You should omit auto-increment field in INSERT statement.


For further information, please see:
Fields that generate numbers automatically in Access[^]
How to reset an AutoNumber field value in Access[^]


Well this is very simple task
if you have watched it carefully see your query you have 6 tables values and 5 parameters so it is always gives you error all the tabled values which you want to insert then must be matched with the parameters suppose you want to insert 3 fields then you can add 3 parameters only

now take a look at your query you have id as a extra field as you mentioned that you have id as a auto increament so just remove that one

and your new query will look like this one

cmd1.CommandText = "INSERT INTO LoginTable(GivenName,Gender,EMail,UserName,Password) VALUES (@GivenName, @Gender, @EMail, @UserName, @Password)";




:)


You can have a look at this examples given at the below link:
syntax-error-on-insert-into-single-column-auto-increment-table[^]


这篇关于使用自动编号在msAccess中插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆