Vous êtes sur la page 1sur 9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
Try our online PLC Simulator- FREE. Click here now to try it. ---------->>>>>Get FREE PLC Programming Tips
your first name your email address Get The PLC Tips Now!

New Here? Please read this important info!!!

PLCS.net - Interactive Q & A > PLCS.net Interactive Q & A > LIVE PLC Questions And Answers

User Name User Name Password PLCS.net Store

Remember Me? Log in

Vije Citect ODBC to Excel problem


Register FAQ Calendar Downloads PLC Reviews

Today's Posts

Search

JUST PUBLISHED... Electronics for PLC People See the details... Finally... a REAL beginners level electronics book written specifically for PLC people! Easy to read and uses 'plain' language! Get $$FREE$$ priority mail shipping too!!! You WILL be glad you did!! Click Here now to order

Thread Tools October 6th, 2009, 03:02 AM

Display Modes #1

Outrage
Member

Vije Citect ODBC to Excel problem

Hi All, I'm trying to set up a connection to move data from Citect to Excel using ODBC and SQL statements but i'm not having much luck. I'm using Citect version 7.0 and Excel 2007. for a test I have the following cicode script and i'm running it on a simple button press: INT FUNCTION Logtosql() INT Test;

Join Date: Jul 2006 Location: Yorkshire Posts: 125

www.plctalk.net/qanda/showthread.php?t=50253

1/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

INT hSQL; hSQL = SQLConnect("DSN=leestest"); Test = SQLExec(hSQL, "INSERT INTO Sheet1 (test, value2) VALUES ('" + IntToStr(TAG1) + "','" + IntToStr(TAG2) + "')") RETURN 0; END I've gone through several amalgamations of this with our rep with no forward progress. The SQLConnect statement appears to link to the spreadsheet as the spreadsheet becomes read only when the script is running but no data is actually transferred to the sheet. I've had a look at the related Knowlege Base items but there's a bit of uncertainty about the syntax for different versions of excel and the 2007 edition doesn't get a look in. I get the following error when I execute the script: SQL Interface - SQL Databae Error - SQLExec() (which i've read directly off the alarms summary) I've tried contacting Citect technical but my licence is out of support and I'm not an SI (we don't do enough SCADA to make it worthwhile plus we have to use whatever our customer specifies which isn't Citect a lot of the time). Can anyone spot where i'm going wrong? or post up some working SQL script that i can paste into my application Best Regards, Lee
Last edited by Outrage; October 6th, 2009 at 03:06 AM.

October 6th, 2009, 05:22 AM

#2

Marsupilami
Member

As you said yourself the problem does not lie within citect but its the syntax of the SQL statement thats the problem. I have never interfaced with excel in this matter. using excell as server and citect connecting to it as SQL client to push data. I don't think there is much in the help about that. But if you find the right SQL stament I am shure it would work. But for the syntax I think you will need too search in the Excel help and use another SQL client to test the sql query. Another way is to turn things around and let excel make a connection to citect trough ODBC. that procedure is described clearly in the citect help. Regards,

Join Date: Jul 2004 Posts: 124

www.plctalk.net/qanda/showthread.php?t=50253

2/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

Marsupilami __________________ Dont take life too seriously you wont survive it anyway

October 6th, 2009, 02:58 PM

#3

Dua Anjing
Member

Join Date: Feb 2008 Location: under the desk looking for a donut... Posts: 414

What happens when you replace the references to TAG1 and TAG 2 with actual values ? so the code reads something like this.. SQLExec(hSQL, "INSERT INTO Sheet1 (test, value2) VALUES ('12','24')") Also have a read about Citect's error fn's,it may be that the above function may return an error number that will shed some more light on what's happening. __________________ Now that food has replaced s*x in my life I can't even get into my own pants

October 7th, 2009, 03:05 AM

#4

kellian
Member

I Believe SQL is for Databases Try DDE commands for Excel In Saying that you might need to add the SQLbegintran(hSql)after the connect and before the action SQLExec() call B

Join Date: May 2002 Location: Capella Posts: 76

October 9th, 2009, 08:49 AM

#5 Quote:

Outrage
Member

Originally Posted by kellian I Believe SQL is for Databases Try DDE commands for Excel In Saying that you might need to add the SQLbegintran(hSql)after the connect and before the action SQLExec() call B

Join Date: Jul 2006 Location: Yorkshire Posts: 125

Hi Kellian, you can use sql to spreadsheets, DDE is no good as you need to specify the destination cells, whereas the insert into command will append data onto a new row.

October 9th, 2009, 08:52 AM


www.plctalk.net/qanda/showthread.php?t=50253

#6
3/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

Outrage
Member

Quote:

Originally Posted by Marsupilami As you said yourself the problem does not lie within citect but its the syntax of the SQL statement thats the problem. I have never interfaced with excel in this matter. using excell as server and citect connecting to it as SQL client to push data. I don't think there is much in the help about that. But if you find the right SQL stament I am shure it would work. But for the syntax I think you will need too search in the Excel help and use another SQL client to test the sql query. Another way is to turn things around and let excel make a connection to citect trough ODBC. that procedure is described clearly in the citect help. Regards, Marsupilami Hi Marsupilami, yes it looks like the syntax, opened up another spreadsheet and ODBC's data from one to the other perfectly, tried the same code in citect with good results but it only works with actual values not tags.....

Join Date: Jul 2006 Location: Yorkshire Posts: 125

October 9th, 2009, 08:55 AM

#7 Quote:

Outrage
Member

Join Date: Jul 2006 Location: Yorkshire Posts: 125

Originally Posted by Dua Anjing What happens when you replace the references to TAG1 and TAG 2 with actual values ? so the code reads something like this.. SQLExec(hSQL, "INSERT INTO Sheet1 (test, value2) VALUES ('12','24')") Also have a read about Citect's error fn's,it may be that the above function may return an error number that will shed some more light on what's happening. Hello Dua Anjing, ive tried that and it works ok in the following format: INT FUNCTION Logtosql() INT Test; INT hSQL; hSQL = SQLConnect("DSN=leestest"); Test = SQLExec(hSQL, "INSERT INTO test (value1, value2)VALUES (500, 300)"); RETURN0; END

www.plctalk.net/qanda/showthread.php?t=50253

4/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

which just transfers fixed values of 500 and 300. i now need to know how to insert tags where the 500 and 300 are....? Cheers, Lee

October 10th, 2009, 06:23 AM

#8

GeoffC
Member

You need to build the insert string first. for example FUNCTION Logtosql() INT Test; INT hSQL; STRING sValue1; STRING sValue2; STRING sInsert; sValue1 = tag1; sValue2 = tag2; sInsert = "INSERT INTO test (value1, value2)VALUES (" + sValue1 + ", " + sValue2 +")"; hSQL = SQLConnect("DSN=leestest"); Test = SQLExec(hSQL, sInsert); RETURN0; END This should get you started

Join Date: Aug 2006 Location: Newcastle Posts: 337

October 12th, 2009, 02:02 AM

#9

Marsupilami
Member

Watch out for regional settings. decmial seperator. those things are always trouble. Marsupilami __________________ Dont take life too seriously you wont survive it anyway

Join Date: Jul 2004 Posts: 124

www.plctalk.net/qanda/showthread.php?t=50253

5/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

October 12th, 2009, 02:25 AM

#10 Quote:

Outrage
Member

Originally Posted by GeoffC You need to build the insert string first. for example FUNCTION Logtosql() INT Test; INT hSQL; STRING sValue1; STRING sValue2; STRING sInsert; sValue1 = tag1; sValue2 = tag2; sInsert = "INSERT INTO test (value1, value2)VALUES (" + sValue1 + ", " + sValue2 +")"; hSQL = SQLConnect("DSN=leestest"); Test = SQLExec(hSQL, sInsert); RETURN0; END This should get you started

Join Date: Jul 2006 Location: Yorkshire Posts: 125

Hey GeoffC / Marsupilami, Thanks for your replies, managed to crack it last thing on Friday - good start to the weekend! For the benefit of future reads A good tool for sorting out the SQL statements is to use MSQuery, an application that runs off the back of excel, you can build a query and test it (spreadsheet to spreadsheet) then cut and paste into citect but it obviously doesnt do the citect strings etc. This is what worked (very similmar to GeoffC's posted code!) INT FUNCTION Logtosql() INT Test; INT hSQL; STRING sArg1; STRING sArg2; sArg1 = tag1 sArg2 = tag2 You are not registered yet. Please click here to register! hSQL = SQLConnect("DSN=leestest"); Test = SQLExec(hSQL, "INSERT INTO test (value1, value2, value3)VALUES ('" + sArg1 + "', '" + sArg2 + "', 'leeoutram')"); SQLDisconnect(hSQL);
www.plctalk.net/qanda/showthread.php?t=50253 6/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

RETURN0; END Despite what my local Citect technical guy said it wasn't capable of, it does work realtime when the spreadsheet is open in Excel in a similar manner to DDE, but gives you a lot more flexibility with your queries. Thanks for your help! Lee

October 12th, 2009, 02:30 AM

#11

Marsupilami
Member

one side note I should have mentioned before. there are known problems with the sql connection functions in citect memory problems connections not closing correctly and so on. they created the PLUSADO sql functions as a workaround. It uses a dll to make SQL calls and works more stable. So if you are seeing problems with your project replace the sql functions with the plus ADO functions. they can be found in the citect toolbox.

Join Date: Jul 2004 Posts: 124

Regards, Marsupilami __________________ Dont take life too seriously you wont survive it anyway

October 12th, 2009, 02:41 AM

#12 Quote:

Outrage
Member

Originally Posted by Marsupilami one side note I should have mentioned before. there are known problems with the sql connection functions in citect memory problems connections not closing correctly and so on. they created the PLUSADO sql functions as a workaround. It uses a dll to make SQL calls and works more stable. So if you are seeing problems with your project replace the sql functions with the plus ADO functions. they can be found in the citect toolbox. Regards, Marsupilami Thanks for the heads up! i'll keep an eye on it.

Join Date: Jul 2006 Location: Yorkshire Posts: 125

www.plctalk.net/qanda/showthread.php?t=50253

7/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

Cheers, Lee

November 14th, 2010, 10:53 AM

#13

mutu26
Member

I have many excel files on my PC. And one day I lost everything on unknown cause. For luck I promptly solved out this issue with the aid of a program. It has quite good capacities for resolving other composite troubles on my view - repair recovered Excel file.

Join Date: Nov 2010 Location: Madrid Posts: 2

Jump to Live PLC Question and Answer Forum


Bookmarks Twitter Reddit Digg del.icio.us StumbleUpon Google

Previous Thread | Next Thread

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

Posting Rules You You You You may may may may not not not not post new threads post replies post attachments edit your posts

BB code is On Smilies are On [IMG] code is On HTML code is Off

Forum Jump LIVE PLC Questions And Answers Go

Similar Topics
Thread Windows 2000 (or citect) Problem Thread Starter Jarno Forum LIVE PLC Questions And Answers Replies 14 Last Post May 14th, 2004 01:05 AM March 7th, 2004 01:25 PM February 14th, 2004 06:28 PM

Ab Plc5 Rio Problem.

fernandes

LIVE PLC Questions And Answers

Citect ODBC error help?

RoTaTech

LIVE PLC Questions And Answers

12

www.plctalk.net/qanda/showthread.php?t=50253

8/9

3/19/12

Vije Citect ODBC to Excel problem - PLCS.net - Interactive Q & A

PLC5/40 Backplane Problem?????

Andrew Evenson

LIVE PLC Questions And Answers

18

August 24th, 2002 07:06 PM

All times are GMT -5. The time now is 10:59 PM. Contact Us - PLCS.net - Text - Top .

www.plctalk.net/qanda/showthread.php?t=50253

9/9

Vous aimerez peut-être aussi