[vtkusers] vtkODBCDatabase used on an Access database file (.mdb) not working.

Jim Peterson jimcp at cox.net
Sat Oct 30 14:50:42 EDT 2010


Donny wrote:
>
> I am trying to access a Microsoft Access file (.mdb) using the 
> standard Microsoft Access ODBC Driver with vtkODBCDatabase but the 
> query returns an error of “Could not execute statement:”.
>
> Here is the code:
>
> //Initialize the latitude and longitude to zero for inspection upon return
>
> double latlon[2] = {0,0};
>
> //This is the format for using the Microsoft Access ODBC Driver as 
> defined here http://www.connectionstrings.com/access#p88
>
> //Driver={Microsoft Access Driver 
> (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;
>
> vtkODBCDatabase* db = vtkODBCDatabase::New();
>
> db->SetDataSourceName("Driver={Microsoft Access Driver 
> (*.mdb)};Dbq=\"C:\\Data\\app.3dd\";Uid=Admin;Pwd=;");
>
> vtkSQLQuery* query = db->GetQueryInstance();
>
> query->SetQuery("Select CenterLon, CenterLat FROM Sites WHERE SiteID = 
> 'KUEX'");
>
> if (query->Execute())
>
> {
>
> while(query->NextRow())
>
> {
>
> latlon[0] = query->DataValue(0).ToDouble();
>
> latlon[1] = query->DataValue(1).ToDouble();
>
> }
>
> }
>
> else
>
> {
>
> //I get an error of Could Not Execute Statement here
>
> const char* err = query->GetLastErrorText();
>
> }
>
> query->Delete();
>
> db->Delete();
>
> return latlon;
>
> The program compiles fine.
>
> I can retreive rows using the .NET OleDb driver from this database 
> using the exact same query so I know the tables are correct.
>
> I would like to see if I can retreive data using VTK.
>
> I am using Windows XP and VTK with C++ in Visual Studio 2005.
>
> Thanks.
>
> Donny Zimmerman
>
Donny,

I don't think VtkODBCDatabase establishes a connection to the database.

you might want to have a look at the documentation for vtkODBCDatabase
http://www.vtk.org/doc/release/5.6/html/a01228.html

follow the links to see also vtkODBCQuery and the tests for examples.

Hope that helps,
Jim



More information about the vtkusers mailing list