C脚本可以写入浮点数,但无法写入字符串,VB脚本估计是连接数据库语句问题,数据库用的windows授权连接,怎么设定VB的UID和PWD,C脚本怎么写入字符串?
VB脚本:
Sub OnClick(Byval Item)
'Private cn As ADODB.Connection
'Private rs As ADODB.Recordset
'Private Sub insertData(nowValue As Double)
Dim database,server
Dim strcn,cn,rs,com
Dim is_SQL
Dim DateTime,Login,Te
Set cn=CreateObject("ADODB.connection")
Set rs=CreateObject("ADODB.Recordset")
Set com=CreateObject("ADODB.Command")
DateTime=Now
Set Te=HMIRuntime.Tags("S7$Program(3)/IVIG_BATCHNO.BATCH_NO01")
Te.Read
Set server=HMIRuntime.Tags("@ServerName")
server.Read
Is_SQL="insert into guf(test2) values('"& Te.Value &"')"
'server=server.Value & "\WINCC"
'database="test"
strcn="Provider=MSDASQL;DSN=test;UID=;PWD="
'strcn="provider=SQLOLEDB.1;DRIVER=SQL SERVER;SERVER="& SERVER &";DATABASE="& database &";UID=;PWD="
'strcn="Driver={SQL Server};Server=.\WINCC;uid=;pass=;database=test"
'strcn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=(local)\\\wincc"
cn.ConnectionString=strcn
cn.Open
com.ActiveConnection=cn
com.CommandText = Is_SQL
com.Execute
Set com = Nothing
'HMIRuntime.DataSet.Add"cn",cn
cn.Execute is_SQL
cn.Close
Set rs = Nothing
Set com = Nothing
End Sub
C脚本:
#include "apdefap.h"
void OnClick(char* lpszPictureName, char* lpszObjectName, char* lpszPropertyName)
{
__object *cn=NULL ;
__object *rs =NULL;
{
char *connstr="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=test;Data Source=(local)\\\wincc";
char sql[80];
char sql1[80];
char sql2[80];
float spd;//test tag
char *test;
cn=__object_create("ADODB.Connection");
rs=__object_create("ADODB.RecordSet");
cn->ConnectionString = connstr;
cn->Open(connstr);
spd=GetTagFloat("TE201101/AI.U");
test=GetTagChar("S7$Program(3)/IVIG_BATCHNO.BATCH_NO01");
if (cn->State == 0)
{
MessageBox(NULL,"database connection fail!","warning",MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_SYSTEMMODAL);
}
sprintf(sql2,"insert into guf (login) values(%f)",Time);
rs->open(sql2,cn);
sprintf(sql,"insert into guf (gw1) values(%f)",spd);
MessageBox(NULL,sql2,NULL,MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_SYSTEMMODAL);
sprintf(sql1,"insert into guf values('%s')",test);
rs->open(sql,cn);
MessageBox(NULL,sql,NULL,MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_SYSTEMMODAL);
if(cn->State != 0)
{
MessageBox(NULL," database connection secessful!","congratulations",MB_OK|MB_ICONEXCLAMATION|MB_SETFOREGROUND|MB_SYSTEMMODAL);
rs->open(sql,cn);
rs->open(sql1,cn);
rs->open(sql2,cn);
//printf("\r\n%s",rs->Field("Temp"));
rs->close();
cn->Close();
__object_delete(rs);
__object_delete(cn);
}
}
}
最佳答案
vbs的资料参考:
WinCC/连通性软件包 V7.4
https://support.industry.siemens.com/cs/cn/zh/view/109736226
WinCC数据开放性
https://support.industry.siemens.com/cs/cn/zh/view/78682604
WinCC、Excel、VBA、脚本、连通性软件包
https://support.industry.siemens.com/cs/cn/zh/view/71676391
WinCC数据报表实现方法介绍
https://support.industry.siemens.com/cs/cn/zh/view/78668993
如何从SQL数据库中通过趋势归档输出变量?
https://support.industry.siemens.com/cs/cn/zh/view/44240726
提问者对于答案的评价:
提供的资料很全,不像有的人,全篇主观观点,毫无建设性,多谢!我阅读资料发现是我VB中调用ADO时,少写了一次连接语句,C中无法写入字符串还是无法解决,再研究一下。
最佳答案作者回复:
很高兴帮到你
我c语言水平也不行,有问题可以论坛交流
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc139032.html