JL-组态王连接SQL Server

准备:组态王6.55版本

           Microsoft SQL Server Management Studio 14.0.17285.0(2017版数据库)

一,登入实例,创建Sa账号(sa账号组态王连接时需要用到

 1,服务器名称:本次测试使用的是安装Wincc创建的实例名称

 2,身份验证:先使用Windows身份验证登录

 

 

 

 

 

 

 二,创建数据库与数据表

 

 

 

 

 

 

 

三,创建ODBC数据源

c:WindowsSysWOW64odbcad32.exe

 

 

 

 

 

 

 

四,组态王应用

1,新建一个画面,在画面命令语言中填写一下函数并测试

 

 2,新建立变量

 

 3,新建记录体

 

 4,在画面中建立一个插入按钮

 运行后点击插入按钮,即可把数据插入

 数据库显示结果为:(这个图片看看就行)

5,查询

插入通用控件KVADODBGrid Class 并将其命名为KVD

 右击控件打开控件属性

 

 

 

 新建一个查询按钮

 效果:

五,时间查询

实现效果:

先插入两个通用控件 Microsoft Date and Time Picker Control 6.0 (SP4),并重新命名。

 

 新建一个按钮,并输入以下代码

string StartY;
string StartM;
string StartD;
string StopY;
string StopM;
string StopD;
string StartDateTime;
string StopDateTime;


StartY=StrFromInt(StartDate.Year, 10 );
StartM=StrFromInt(StartDate.Month, 10 );
StartD=StrFromInt(StartDate.Day, 10 );
StopY=StrFromInt(StopDate.Year, 10 );
StopM=StrFromInt(StopDate.Month, 10 );
StopD=StrFromInt(StopDate.Day, 10 ); 


StartDateTime="'"+StartY+"-"+StartM+"-"+StartD+"'";
StopDateTime="'"+StopY+"-"+StopM+"-"+StopD+"'";



KVD.Where="查询日期 between "+StartDateTime +"and" +StopDateTime ;
KVD.FetchData();
View Code
原文地址:https://www.cnblogs.com/Luck1996/p/12049761.html