views:

68

answers:

2

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?

A: 

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.

Vishal Seth
thanks, but it didnt work.Changed my approach to using MAX() to retrieve the highest value then increment and Insert
tecno
Max will probably cause issues... Use 'Select @@identity'... Can you pos the snippet?
Paul Kohler
A: 

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.

machine elf
I gather from your comments, it works?
machine elf