stupid question regarding database lookup

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
e_patsellis
Member
Posts: 28
Joined: Sun Jun 15, 2003 12:33 pm
Location: shelbyville, IL
Contact:

stupid question regarding database lookup

Post by e_patsellis »

Scott,

Hopefully it just that it's late, but is there a somwhat easy way to lookup a record # in a .mdb database and set several properties based on that record without resorting to writing a device plugin???

erie
ScottBot
Site Admin
Posts: 2787
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Post by ScottBot »

Erie,



You can use a Script Device to do this. Here's a sample that shows the basics. You would need to change the various parts of the script to point to your DB and data, but it should give you an idea of what to do.


Set dbConn = CreateObject( "ADODB.Connection" )

' Set path to MDB file in variable
Dim pathToDB
pathToDB = "\Program Files\HouseBot\Config\HBData.mdb"

' Open connection to DB
dbConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & pathToDB

' Execute query for the Description of the System Time Device
Set rs = dbConn.Execute( "select Description from Devices where Name='System Time'" )

' Check the result
if (rs.EOF) Then
MsgBox( "No Data Found" )
Else
MsgBox( rs("Description") ) ' Show result in message box

' Now set a Property Value with the new value.
SetPropertyValue "DB Update (Script).Test Value", rs("Description" )
End If
Scott
Post Reply