
- Odbc excel file how to#
- Odbc excel file install#
- Odbc excel file code#
If you need to do something like that you´re bound to use CRecordset the "usual" way. So any attempts to change the data or to move back will fail horribly. If using an underived CRecordset it needs to be readonly, foreward only. The result of an attempt to do so is some mumbling about missing registry keys. Earlier versions will not be able to use a DSN that actually isn´t installed. Using a pseudo DSN only works with ODBC Admin V3.51 and higher. You must use an ODBC Admin version 3.5 or higher.
Odbc excel file install#
install an ODBC-driver called "MICROSOFT EXCEL DRIVER (*.XLS)" (or something like that).
Odbc excel file code#
In order to get the code below going you have to Reading out the result is done by CRecordset::GetFieldValue(). The data to get is defined by the SQL statement you put into CRecordset::Open().
To use CRecordset the plain way you have to use a readonly, foreward only recordset. For an example see CReadExcelDlg::GetExcelDriver() below. If it isn´t, a call to SQLGetInstalledDrivers() will show all the installed drivers. This, of course, implies that the name of the ODBC-Driver is exactly known. Omiting the DSN tag in the connect string of CDatabase:Open() gives the opportunity to refer the ODBC-Driver directly using its name so we don´t have to have a DSN registered. If you open "ReadExcel.xls" from the attached demo project and look up the names, you´ll see what I mean. This means that a sheet isn´t necessarily the same as a table in a "real" database. There can be more than one "table" on a worksheet. One way to let ODBC know what data is in there is to name a range of data on a worksheet using "Insert/Names" from Excel´s menu. Odbc excel file how to#
Unfortunately they don´t state how to do this exactly.
According to Microsoft, an Excel sheet of version 4.x and later can only be read by ODBC if a database range is defined. That is because if I always have to create a class for every single table I want to use, I´ll end up with lots of rather unnecessary code enlarging my app´s exe. The last problem I´m dealing with here is generally doing ODBC reading using CRecordset without deriving from it. This is not very useful because you don´t always know the name of the Excel file from the start. If somewhere out there finds there´s a way to do the reading whithout the formatting, please let me know.Īnother problem is the DSN you need to have installed in your ODBC Admin. Microsoft refers to this in one of their KB papers. The main problem is that you can´t read an Excel file without previously having some formatting done. Download demo project - 20 Kb The ProblemĪfter contributing that article about writing into an Excel file I got tons of requests about how to read from one.