This code has several problems:
1) Too many input parameters as mentioned above.
2) You need quotes arround your parameter names: command.Parameters.Add("strMedium" ... for all your parameters. This is why you are getting an error when executing the command.
3) You are reading 6 columns ( reader(0) - reader(5) ) when your select statement only asks for 3 columns per row: strMedium, sndDeviceAddress, typEvent. Hence, when you do fix the parameter issues you will get an error when reading the rows :) Speed is probably not a factor, so I would just use the column names instead of the ordinal position for ease of understanding, etc.
4) As a side note, you are also naming an integer (Int32) variable int, which I assume is not a keyword in VB.NET That wouldn't compile in C#, but I guess it must compile and work fine in VB.NET. Looks funny is all :)
VB.Net is not my thing, but here is a cut at rewriting the code. Unfortunately, I don't have time to create an Access Database to test:
Private Function Check() 'CheckX10Alerts(ByVal X10_RecvCMD As String, ByVal sndDeviceAddress As String, ByVal typEvent As String)
'Prepare to look for matching alert database Dim int As Int32
bolAlertsEnabled = True If bolAlertsEnabled = True Then Using connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Dot_Net_Projects\Visual_Basic\aiHome\Website\App_Data\aiHome.mdb;") Dim command As New OleDbCommand("SELECT strMedium, sndDeviceAddress, typEvent FROM x10_Triggers WHERE strMedium = AND sndDeviceAddress = AND typEvent = ", connection)
command.Parameters.Add("strMedium", OleDbType.Char, 10).Value = strX10_Command command.Parameters.Add("sndDeviceAddress", OleDbType.Char, 3).Value = strX10_DeviceAddress command.Parameters.Add("typEvent", OleDbType.Char, 12).Value = strX10_RecvCMD
connection.Open()
Dim reader As OleDbDataReader = command.ExecuteReader
While reader.Read() int = int + 1 Console.WriteLine(reader("strMedium").ToString()) Console.WriteLine(reader("sndDeviceAddress").ToString()) Console.WriteLine(reader("typEvent").ToString()) Console.WriteLine(int) End While reader.Close() End Using
End If
End Function
Good luck. Hope this helps,
Dave
|