I modified it slightly as I found another header file is needed
#include <Origin.h>
#include <..\Originlab\query_utils.h>
int testdb()
{
Object ocora;
try
{
ocora = CreateObject("ADODB.Recordset");
}
catch(int nError)
{
out_str("Failed to create ADODB.Recordset");
return FALSE;
}
// Import stars.mdb from the Origin Samples folder
string strDatabaseFile = GetAppPath(1) +
"Samples\\Import and Export\\stars.mdb";
// Prepare the database connection string
string strConn;
strConn.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=%s;
User ID=admin; Password=;", strDatabaseFile);
// Prepare the SQL string
string strQuery = "Select Stars.Index, Stars.Name, Stars.LightYears,
Stars.Magnitude From Stars";
ocora.CursorLocation = adUseClient;
try
{
ocora.open(strQuery, strConn, 1, 3);
}
catch(int nError)
{
out_str("Failed to open Oracle database");
return FALSE;
}
Worksheet wks;
wks.Create();
//put data into the worksheet.
BOOL bRet = wks.PutRecordset(ocora);
out_int("bRet = ", bRet);
return bRet;
}
Do you have to use Origin C? We need to prepare better example, but LabTalk is much easier.
Have you read this?
http://www.originlab.com/doc/Tutorials/ImpData-from-DB
and the part about using LabTalk in SQL Editor?
CP