访问插入查询
我正在使用 C# 写入/读取 Access 2007 数据库。该表是 ID - 自动编号 [pkey] Fname - 文本 Lname - 文本 地址 - 文本
我使用的查询字符串是
"Insert into TblMain (Fname,Lname,Address) Values ('"+fname+"','"+lname+"','"+adrs+"')"
没有返回错误,查询执行但数据未添加到数据库中。
使用没有自动编号数据列的表插入可以完美地工作。
我缺少什么?
I am using C# to write/read to an Access 2007 Database. The table is
ID - AutoNumber [pkey]
Fname - Text
Lname - Text
Address - Text
The query string I Use is
"Insert into TblMain (Fname,Lname,Address) Values ('"+fname+"','"+lname+"','"+adrs+"')"
No errors are returned, the query executes but data is not added to the db.
Inserting to table using which does not have an autonumber data column works perfectly.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用表名的别名。
Use an alias for the table name.
尝试运行查询,同时将字段名称放在方括号内。
我记得以前我遇到过类似的情况,其中我的字段名称之一是“zone”(我想我没记错),我无法弄清楚为什么 ADO 不会让查询运行。后来我发现他们的ADO库的实现与该字段名称有一些冲突。
Try running the query while placing field names under square brackets.
I remember in old days I faced similar situation where one of my field name was "zone" (I think I remember correctly) and I could not figure out why ADO will not let the query run. Later on I found that their implementation of ADO library had some conflict with that field name.
也许尝试包含 ID 字段并为要附加的记录提供唯一的 ID 号?
http://msdn.microsoft.com/en-us/library/bb208861。 ASPX
Maybe try including the ID field and give unique ID numbers to the records being appended?
http://msdn.microsoft.com/en-us/library/bb208861.aspx
我解决了这个问题[插入查询]:
[软件:Access 2013]
I solved this problem [Insert Query]:
[Software: Access 2013]