搬家第41天-citect2018使用cicode添加access记录

一 Access中新建一个2003版本数据库report,其下新建一张表mytable,表的字段如下:

二 citect中新建变量如下

三 写一个cicode程序,给变量赋值
FUNCTION Setvalue()
temp1=TimeSec(TimeCurrent())
temp2=TimeSec(TimeCurrent())+10
temp3=TimeSec(TimeCurrent())+20
temp4=TimeSec(TimeCurrent())+30
press1=TimeSec(TimeCurrent())+5
press2=TimeSec(TimeCurrent())+15
press3=TimeSec(TimeCurrent())+25
press4=TimeSec(TimeCurrent())+35
flow1=TimeSec(TimeCurrent())+8
flow2=TimeSec(TimeCurrent())+18
END
这里只是为了看效果,随便写了赋值语句
 
四 写数据库添加记录的语句
FUNCTION AddReordToAccessDB()
hSQL=SQLConnect("DSN=myaccess")
STRING sqlstr1,sqlstr2
IF hSQL<>-1 THEN
//Message("Information","连接Access数据库成功",48)
sqlstr1="insert into mytable(curdate,curtime,temp1,temp2,temp3,temp4,press1,press2,press3,press4,flow1,flow2) values('"  
sqlstr2=Date() + "','" + TimeToStr(TimeCurrent(),0) + "'," + RealToStr(temp1,5,1) + "," + RealToStr(temp2,5,1) + "," + RealToStr(temp3,5,1) + "," + RealToStr(temp4,5,1) + "," + RealToStr(press1,5,1) + "," + RealToStr(press2,5,1) + "," + RealToStr(press3,5,1) + "," + RealToStr(press4,5,1) + "," + RealToStr(flow1,5,1) + "," + RealToStr(flow2,5,1) + ")"
//将记录写入数据库
hStatus = SQLExec(hSQL, sqlstr1+sqlstr2)
IF hStatus <> 0 THEN
Message("Information", SQLErrMsg(), 48)
END
SQLDisconnect(hSQL)   
ELSE
Message("Information", SQLErrMsg(), 48)
END
END
 
五 为了定期执行这些脚本,还需要在citect中定义事件
每秒赋值一次,添加记录一次。
 
为了让事件有效执行,还需要在计算机想到中使能这些事件
 
运行后就能看到效果了
 
posted @ 2021-03-10 20:10  来自金沙江的小鱼  阅读(238)  评论(0编辑  收藏  举报