nhờ các bạn trên diễn dàn thành thạo về wincc giup đỡ!
mình có một đoạn code nhỏ viết bằng vb, đã kiểm tra nhiều tài liệu và tham khảo các bạn đã từng làm có thể nói là không sai.nhưng khi đưa và wincc thì không xuất được thông số ra sql hay accsess được ,mình đã kết nối odbc như video hướng dẫn trên youtube của ban" thang nguyen". bạn nào đã từng làm thành công rùi thì giúp mình với mình còn gà lắm
cám ơn mọi người nhiều và đây là code
Sub OnLButtonDown(Byval Item, Byval Flags, Byval x, Byval y)
Dim objConnection
Dim strConnectionString
Dim sohieucongthuc
Dim congthuc
Dim meso
Dim khoiluongdat
Dim khoiluongthuc
Dim saiso
Dim strSQL
Dim objCommand
‘strConnectionString = "Provider=MSDASQL;DSN=WINCCSQL;UID=;PWD=;"
strConnectionString ="Driver={SQL Native Client};Server= ADMIN-A5C4B5D29;Database=WINCCSQL;Trusted_Connection=yes ;"
sohieucongthuc=HMIRuntime.Tags ("sohieucongthuc").Read
meso=HMIRuntime.Tags ("meso").Read
congthuc=HMIRuntime.Tags ("congthuc").Read
khoiluongdat=HMIRuntime.Tags ("khoiluongdat").Read
khoiluongthuc=HMIRuntime.Tags ("khoiluongthuc").Read
saiso=HMIRuntime.Tags ("saiso").Read
strSQL = "INSERT INTO dbo.baocao (thoigian,sohieucongthuc,congthuc,meso,khoiluongda t,khoiluongthuc,saiso) VALUES (" & SQL_TimeString(Now)&","& HMIRuntime.Tags ("sohieucongthuc").Read &","& HMIRuntime.Tags ("congthuc").Read &","& HMIRuntime.Tags ("meso").Read &","& HMIRuntime.Tags ("khoiluongdat").Read &","& HMIRuntime.Tags ("khoiluongthuc").Read &","& HMIRuntime.Tags ("saiso").Read &");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand.ActiveConnection = objConnection.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing
End Sub
Đánh dấu