开发者

Access Insert Query

开发者 https://www.devze.com 2022-12-24 14:48 出处:网络
I am using C# to write/read to an Access 2007 Database. The table is ID - AutoNumber [pkey] Fname - Text

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 int开发者_JS百科o 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?


Use an alias for the table name.


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.


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

If your destination table contains a primary key, make sure you append unique, non-Null values to the primary key field or fields; if you do not, the Microsoft Access database engine will not append the records.

If you append records to a table with an AutoNumber field and you want to renumber the appended records, do not include the AutoNumber field in your query. Do include the AutoNumber field in the query if you want to retain the original values from the field.


I solved this problem [Insert Query]: [Software: Access 2013]

CurrentDb.Execute "INSERT INTO [tblquery] ([stdid], [stdname])" _
& "VALUES ( " & Me.txtID & ", " & Me.txtName & ")"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号