On my current project I have to connect to a legacy FoxPro2 database. I know nothing about FoxPro but it was fairly easy to connect to and use in ADO.NET. I had a few stumbling points that I thought I would share in case you have to connect to one.
1. Named parameters are not used by oledb/odbc commands. They are ordinal and represented by question marks:
command.commandText = "insert into users (firstName, lastName) values (?, ?)"
The commands then need to be added in the correct order:
command.parameters.add("@firstName", customer.firstName) command.parameters.add("@lastName", customer.lastName)
I know I show the parameters as named in the add() method but I could call them whatever I wanted. It is imperative that they are in the right order otherwise it will not work properly. I am under the impression that only SqlCommands take named parameters but I could be wrong on that.
2. When you get "OleDbException: Variable is not found". It means that the column you are querying does not exist (I had a small typo in my query and it took me a long time to figure this out).
3. When doing a query like this:
insert into users (firstName, lastName) values (?, ?)
yet there is a column called PhoneNumber in the table you will get the error:
"Field PHONENUMBER does not accept null values"
From my reading FoxPro does not have a null type so it fails on this query. The only way I got this to work was to switch from an oledb provider to an ODBC provider and uncheck the "Null" checkbox in the ODBC options for my foxpro DSN.
4. The error message: "Driver Not Capable" occurs when you try to insert a complex type (i.e. an object) instead of a primitive. Not the most descriptive error but easy enough to fix.
5. When setting up a foxpro ODBC connection you will get an error saying you need to download the latest driver. You should download the latest Visual Foxpro Driver (yes even if you using FoxPro not Visual FoxPro). Then configure your connection using the FoxPro VPF Connection. Under database type there will be two options to use a DBC database (visual FoxPro) or to use a Free Table Directory. Use the Free Table Directory option as legacy FoxPro creates a file per table in a set directory and that is your "database".
6. This applies to everyone. CODE TO INTERFACES. By coding to the IConnection, ICommand, etc. interfaces my switched back and forth between odbc and oledb took seconds not days.