PDA

View Full Version : ADODB, SQL, INSERT - force the type of inserted data



JimmyTheHand
05-26-2008, 07:00 AM
Hi All,

I'm trying to use an Excel workbook as database, and ADODB to do database management, including SELECT, INSERT and UPDATE operations.

The 1st field of my table is, very imaginatively, called 'ID'. It is a counter, increased by one with each new record. Through some experimenting I found that the data type of a newly inserted ID depends on the type of the previous ID. (This probably holds for any other fields as well.)

For example, if there are any number of records in the DB, the new ID will be a numeric value, because the previous value in that column is numeric. If there are no records, then the new ID will still be a number, but stored as string, because the previous value in that column is the field name ("ID"), which is string. This troubles me a lot, because other parts of my program, especially queries, are expecting numeric data as ID, and so the program crashes.

I would like to be able to handle empty DBs as well, but right now my only way to do it is to prepare the empty DB, and insert a "0th record" to provide the necessary data formats.

So does anyone know a way of forcing the type of the inserted data to Long?

Thanks in advance,

Jimmy