Problem with DefaultView.Rowfilter

Rexyss

Member
Joined
Jan 3, 2008
Messages
12
Programming Experience
Beginner
Hi. I try to use Rowfilter.


This works fine:

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = 20304050")
But this is NOT working:

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = Textbox2.Text")

Is there a way do use a Variable or Textbox input with RowFilter??
 
VB.NET:
dim s as string = "hello" & stringvariable
 
Assuming you posted it correctly,

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = Textbox2.Text")

you could try

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = " & Textbox2.Text)
 
although have you spotted your mistake?
VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = Textbox2.Text")
anything within the quotes (" ") is the filter...so basically the code was as it's displayed right there - what's the filter? it's MobileNumber = Textbox2.Text

However, as JohnH posted, you are best off setting a variable first, I find it's "cleaner" and easier to track back any errors you may come across at a later date (i.e. regarding data types)

VB.NET:
Dim strMobile as String = me.textbox2.text
RepairTable.DefaultView.Rowfilter = ("MobileNumber = " & strMobile)

It's always best to declare the variable first, get use to them as it's the best way to code parameterised queries....
 
Actually, I don't think it's better to get a value from a property into a variable then use it in a expression... it was just pseudo code how to add a string and something else of type String. The code editor/intellisense today is so good you see both when coding and when debugging/breaking what type any object is, so there is no need to type it out, in my opinion. There is one exception soemtimes, when the property value (or function return) is used multiple times and it takes much time for the object to produce the value, in that case one would perhaps cache the property value in a local variable first.
Another way to add two strings together is the String.Concat shared method, by the way.
 
Hi. I try to use Rowfilter.


This works fine:

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = 20304050")
But this is NOT working:

VB.NET:
RepairTable.DefaultView.Rowfilter = ("MobileNumber = Textbox2.Text")

Is there a way do use a Variable or Textbox input with RowFilter??


Dim s as String = "2 + 2"


Tell me.. what is the content of s:

a) "2 + 2"
b) "4"


(If you answered b), um.. maybe programming isnt for you)
 
Back
Top