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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Executing a .ODQ from Origin C

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
hermiduca Posted - 07/27/2017 : 2:08:00 PM
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!
3   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 07/29/2017 : 11:07:10 PM
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
hermiduca Posted - 07/28/2017 : 07:47:21 AM
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
cpyang Posted - 07/28/2017 : 12:29:54 AM
It will be simpler to use LabTalk for such, see

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

CP

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000