Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIKE operation

Status
Not open for further replies.

shannanl

IS-IT--Management
Apr 24, 2003
1,071
0
0
US
I have a text box that the user enters a persons pin # in. This pin # is a numeric value. I am attempting to filter a dataview based on this text box value. I am using P_pin LIKE '" & textbox1.text & "%'.

I receive an error that says the LIKE operation cannot be performed on int32 AND system.string. How can I get around this?

Thanks,

Shannan
 
Try doing the comparison against [tt]P_pin.ToString[/tt]


Hope this helps.

[vampire][bat]
 
I still receive the same error using :

P_pin LIKE '" & textbox1.tostring & "%'

Thanks,

Shannan
 
[tt]P_pin.ToString[/tt].


[tt]TextBox1.Text[/tt] should still be correct.


Hope this helps.




[vampire][bat]
 
I am using the following :

Dim dvData As New DataView(dsData.Tables("Patients"))
dvData.RowFilter = "P_PIN LIKE '" & txtPin.Text & "%'"
dgPatient.DataSource = dvData

Ii don't think I can use "P_PIN.tostring" in this context can I?

Thanks,

Shannan

 
The field in the database is numeric. Don't use like use = and forget the '. Since it's numeric like has no meaning.
 
I tried two different things (see below). I receive a "Missing operand after MOD operator" error.

Thanks,

Shannan



#1
Dim dvData As New DataView(dsData.Tables("Patients"))
dvData.RowFilter = "P_PIN = " & Val(txtPin.Text) & "%"
dgPatient.DataSource = dvData

#2

Dim dvData As New DataView(dsData.Tables("Patients"))
dvData.RowFilter = "P_PIN = " & txtPin.Text & "%"
dgPatient.DataSource = dvData
 
If the value is a single number then the percent sign is not needed.
If the user enters only part of a pin then you will need to handle it like a number but the percent sign is a wild card for the like command.
djj
 
It is a 8 digit number and I will need to use the wildcard but it does not seem to work with it. I can take out the wildcard but then the user must enter an exact match.

Shannan
 
How about:

Code:
Dim dvData As New DataView(dsData.Tables("Patients"))
dvData.RowFilter = "P_PIN LIKE " & txtPin.Text & "%"
dgPatient.DataSource = dvData

Not sure if it'll work. You may have to convert the P_PIN field to a string in order to use the LIKE opperator. I'm not sure on that syntax though.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
It appears that you can only search numeric using the typical less than, greater than, equals to, etc. operators.
 
In the SQL where you get the data in dsData.Tables("Patients"), use the CAST operator to select the P_PIN field and convert it to a string. Then, you can use the LIKE operator with a wildcard on this string. Here's the SQL for this:

Select *, CAST(P_PIN as nvarchar(8)) as P_PINString from tblPatients

Then the dataview's rowfilter would be:

"P_PINString LIKE '" & textbox1.text & "%'"

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
If it is always 8 chars and numeric, could you do:

Code:
Dim LowNum as String
Dim HighNum as String
Dim FilterStr as String

LowNum = textbox1.Text.PadRight(8, "0")
HighNum = textbox1.Text.PadRight(8, "9")

FilterStr = String.Format("P_PIN >= {0} AND P_PIN <= {1}", LowNum, HighNum)

--Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top