strSQL1= "select * from [生产数据] Where sj >= " & startDate & " and sj <= " & endDate & " Order By sj ASC"
Is that true? I still have no data, and I can't query it.
I want to query the data in the SQL database according to the time period, the following is the code I wrote, the universal user to help see where the query statement is wrong leading to the query can not come out. Control 2 and Control 3 are WINCCdtp controls
Sub OnClick(ByVal Item)
Dim conn '定义类对象
Dim SCon '定义数据库连接字符串
Dim oRs1 '定义获取到的数据集
Dim oCom
Dim strSQL1
Dim m,i,j,k,DATE1,date2,date3,date4,date5
Dim startDate,endDate
Set date2=ScreenItems("控件2")
date4 = FormatDateTime(date2.Value,2)
Msgbox(date4)
startDate=date4 & " 00:00:00"
Set date3=ScreenItems("控件3")
date5 = FormatDateTime(date3.Value,2)
endDate= date5 & " 23:59:59"
'---------------------打开数据库 --------------------'
sCon= "Provider=SQLOLEDB; Integrated Security =SSPI;Persist Security Info=False; Initial Catalog=生产统计; Data Source=ZKCD\WINCC"
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString = sCon
conn.CursorLocation = 3
conn.Open
Set oRs1 = CreateObject("ADODB.Recordset")
Set oCom = CreateObject("ADODB.Command")
oCom.CommandType = 1
Msgbox(endDate)
'---------------------查询数据库 --------------------'
'strSQL1= "SELECT * FROM [生产数据]"
strSQL1 = "SELECT * FROM [生产数据] WHERE sj BETWEEN ”" & startDate & "” And ”" & endDate & "” ORDER BY sj "
Set oCom.ActiveConnection = conn
oCom.CommandText = strSQL1
Set oRs1 = oCom.Execute
m = oRs1.RecordCount
MsgBox("查询到表格共有" & m &"行数据")
0 Answer
strSQL1= "select * from [生产数据] Where sj >= " & startDate & " and sj <= " & endDate & " Order By sj ASC"
Is that true? I still have no data, and I can't query it.
这家伙很懒,什么都没留下...