It looks like your multiple-condition Select
has way too many quotes in it. According to this question, you should just be able to do something like this:
.Select("Floor ='3' AND Building ='Mall'")
I'm not sure if the capitalization matters there, but you'd might as well make the AND
all caps while you're at it.
You can also do this with LINQ using AsEnumerable
and Where
:
For Each dtrow In FbuildingSettings.camButtonDtable.AsEnumerable.Where(Function(dr) dr("Floor") = "3" AndAlso dr("Building") = "Mal
UPDATE: Based on the update to your question, it looks like nBtn.Name
is expecting one type, and your statement is implicitly trying to set it to something else. If you set Option Strict On
at the top of your file, VB will force you to cast explicitly where necessary when setting/using your objects. If you don't want to do that, that's fine, but it might come down to doing something like this:
nBtn.Name = dtrow("ButtonText").ToString & dtrow("ID").ToString
or this:
nBtn.Name = String.Format("{0}{1}", dtrow("ButtonText").ToString, dtrow("ID").ToString)
Also, check to make sure that dtrow("ButtonText")
and dtrow("ID")
actually contain a value (i.e., that they aren't DBNull.Value
) If that's the problem, then you can use temporary variables along with If
statements to set them accordingly:
Dim buttonText As String = String.Empty
Dim id As String = String.Empty
If dtrow("ButtonText") IsNot DBNull.Value Then
nBtn.Name &= dtrow("ButtonText").ToString
End If
If dtrow("ID") IsNot DBNull.Value Then
nBtn.Name &= dtrow("ID").ToString
End If
Note, though, the ToString
will make sure that VB grabs the String
representation of the value in your DataRow
. Otherwise, I think it just tries to use the type based on what was added when the DataRow
was created.