JL-組態王連接SQL Server


准備:組態王6.55版本

           Microsoft SQL Server Management Studio 14.0.17285.0(2017版數據庫)

 

一,登入實例,創建Sa賬號(sa賬號組態王連接時需要用到

 

 1,服務器名稱:本次測試使用的是安裝Wincc創建的實例名稱

 2,身份驗證:先使用Windows身份驗證登錄

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 二,創建數據庫與數據表

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

三,創建ODBC數據源

c:\Windows\SysWOW64\odbcad32.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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM