I've created a database and a table with no records. How do I add a new record using ADO?
Printable View
I've created a database and a table with no records. How do I add a new record using ADO?
Personal preference is using SQL statements. Say you have a table like (assuming you're using Access):
Inserting would be:Code:TableName
Field1 (Auto number)
Field2 (String)
Field3 (Numeric)
The first set of parentheses specify the fields to insert into & the second the values. In this example, you have to specify the field names as the first field is autonumbered, and as such you can't specify the value to insert. Assuming that it wasn't autonumbered & was say numeric, you could forgo the field name list.Code:INSERT INTO TableName (Field2, Field3) VALUES ('ABC', 123)
Next part, the values themselves. The second field (Field2) is a string. These values are prefixed & suffixed with single quotes - you'll get lovely errors if you don't use these. Now the third field, the numerics aren't prefixed & suffixed - again, you'll get lovely errors in Access if you treat numerics as strings.
Nice, short tutorial on inserts. I think maybe you should go play on google & search for SQL tutorials, as there's a helluva lot more to SQL than just inserting.