The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Executing a .ODQ from Origin C
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hermiduca

Paraguay
2 Posts

Posted - 07/27/2017 :  2:08:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 9
Operating System: Windows 7

Hi all,

My .ODQ contains the following:

[DataSource]ConnectionString
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MODI_RT_DATA;Data Source=REP\HYCONMD;User ID=;Password=
[SQL]
SELECT LNKT_C_PIO_id, r_Avg, dt_Stamp
FROM MODI_RT_DATA.dbo.R_LA_2
WHERE LNKT_C_PIO_Id = 10115267 or LNKT_C_PIO_Id = 10115287
[Options]
6
[BeforeScript]


How can I use this from Origin C to import the data in a worksheet?

Thanks a lot!

cpyang

USA
1406 Posts

Posted - 07/28/2017 :  12:29:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It will be simpler to use LabTalk for such, see

http://www.originlab.com/doc/X-Function/ref/dbEdit

CP
Go to Top of Page

hermiduca

Paraguay
2 Posts

Posted - 07/28/2017 :  07:47:21 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for answering CP!

Here is a link where explains how to import data from database with Origin C:

http://www.originlab.com/doc/OriginC/guide/Importing-from-a-Database

I tried to do this example, everything related with the database compile fine (In this example: Importing stars.md file, preparing the database connection string and Preparing the SQL string). But my problems stared when I tried to import all the data in a worksheet, origin said: 'try' is unknown keyword for declaration statement.
How should I import data without using an ADODB.Reocrdset object?

Regards!

Hermi
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 07/29/2017 :  11:07:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000