Page 1 of 1

stupid question regarding database lookup

Posted: Tue Aug 26, 2003 1:38 am
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

Posted: Tue Aug 26, 2003 8:38 am
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