Nu heb ik gehoord dat je hiervoor in PHP MySQL escape string kan gebruiken (klok klepel auw) maar hoe doe ik dit in VB (Me=VB Rookie)
Code: Select all
Imports System.Data
Imports MySql.Data.MySqlClient
Dim Public ID As String = "statusCallBack.vb"
Sub checkStatus(ByVal aParm as Object)
dim stat, hc, dc, hdc,refID, sName as String
Dim conn As MySqlConnection
Dim myCommand As New MySqlCommand
Dim varDate as String
Dim varTime as String
Dim varDeviceName as String
Dim varDeviceCode as String
'---------------------------------------------------------------
'PLACE THIS STATEMENT IN YOUR STARTUP SCRIPT
' hs.RegisterStatusChangeCB "statusCallBack.vb","checkStatus"
'---------------------------------------------------------------
hc = aParm(0)
dc = aParm(1)
stat = aParm(2)
refID = aParm(3)
hdc = hc & dc
Dim device
Dim dn
Dim type as String
Dim tijd
tijd = Datepart("yyyy",Now()) & "-" & Right("0" & DatePart("m",Now()),2) & "-" & Right("0" & DatePart("d",Now()),2) & " " & Right("0" & DatePart("h",Now()),2) & ":" & Right("0" & DatePart("n",Now()),2) & ":" & Right("0" & DatePart("s",Now()),2)
device = hs.GetDeviceByRef(refID)
dn = device.name
'
'Detect type of device
'
Select Case (hc)
Case "\"
type = "RFXcom"
Case "["
type = "RFXcom"
Case "]"
type = "K8055"
Case "_"
type = "Chromoflex"
Case "A"
type = "Kaku"
Case "B"
type = "Bleutooth"
Case "F"
type = "Grafiek"
Case "P"
type = "Schakelaar"
Case "Q"
type = "Z-Wave"
Case "V"
type = "Virtual Uptime"
Case "Z"
type = "Server"
Case "^"
type = "Plugwise"
End Select
'hs.writelog(ID,"House Code: " & hc & " Device Code " & dc & " Status: " & stat & " Device Value: " & hs.DeviceValue(hdc) & " Device String: " & hs.DeviceString(hdc) & " Name: " & dn & " Type: " & type & " Time: " & tijd)
conn = New MySqlConnection()
conn.ConnectionString = "server=127.0.0.128; user id=homeseer; password=zegiknie; database=databeest"
Try
conn.Open()
'hs.writelog ("mySQL", "Connection Opened Successfully!")
myCommand.CommandText = "INSERT INTO tbldevices (hc,devicename,type,dc,value,status,ts)" & " VALUES ('" & hc & "','" & dn & "','" & type & "','" & dc & "','" & hs.DeviceValue(hdc) & "','" & stat & "','" & tijd & "')"
myCommand.Connection = conn
myCommand.ExecuteNonQuery()
'hs.writelog ("mySQL", "Logged to database: " & varDeviceName & ", " & varDeviceCode & ", " & iStatus)
conn.Close()
Catch myerror As MySqlException
hs.writelog ("mySQL", "Error Connecting to Database: " & myerror.Message)
End Try
End Sub
Code: Select all
2-4-2013 18:05:45 - mySQL - Error Connecting to Database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Slaapkamer T','RFXcom','2','181','2','2013-04-02 18:05:45')' at line 1