0

I am using this line:

For Each dtrow In FbuildingSettings.camButtonDtable.Select("Floor ='3'")

to select all items from Floor = 3
How can I add another argument the states..

.Select(Building = Mall and Floor = 3)

where it will find all data that has Mall as building, then get all from the third floor.
I tried something like : .Select("Floor ='3' And Building ="'"Mall"'"") - but it seems I am doing it wrong. I am not really good in sql.
Also, I am planning on using variables for Mall and 3.. If you would be so kind, make it that way thanks :)

UPDATE: I tried valverij answer and it comes down to this: (though Floor=3 code is still working) enter image description here

2
  • 1
    by roper did you mean proper in the title? Commented Jan 28, 2014 at 3:05
  • sorry about that :) that wasn't my title at first, maybe I've accidentally deleted P. Commented Jan 28, 2014 at 3:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

does making either of them in the front make a difference?
I don't think so, but the syntax for DataTable.Select might be slightly different than regular SQL. Here's an article outlining the use of the row filter syntax. It's in C#, but the syntax for the Select should be the same: csharp-examples.net/dataview-rowfilter Keep in mind that NULL records might throw it off.
thanks for the link, can you check my updated question?
@AdorableVB, it looks like there's an implicit typing issue between nBtn.Name and the value in your DataRow. I've updated my answer to include that.
got it, although, I still get the same error, I am pretty sure that there is something wrong with the for each line. Is there any other way that gives the same output that I want?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.