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!

vb.net cannot perform 'like' operation on system.int32 and system.string 2

Status
Not open for further replies.

zytalyb

Programmer
Oct 17, 2011
15
0
0
DE
Hi all, I use the VB.Net 2012 and connected to an Access Database, that has only one Table (ex. Ges)the Table has 16 column (5 of them are String and the others are Integer data types). I have defined a DataView and want to Filter all the Data according to the Text that I type in the corresponding TextBoxes. So I have designed in the form, 16 TextBoxes and added a <btn Search> and a DataGrid. I want the following:
- When I clear the texts in the textBoxes and type any Text in the corresponding TextBox, and click the btnSearch, so the Filter must be done and I get the data in the GridView.

My Code:

Dim Name As String = txtName.Text
Dim SollStd As Integer = Val(txtSollStunden.Text).ToString()
.....etc
Dim tvw As New DataView(tbl)
tvw.RowFilter = String.Format("Name LIKE '{0}' AND SollStd LIKE '{1}' AND Column3 LIKE '{2}' AND Column4 LIKE '{3}' AND Column5 LIKE '{4}'" & "AND Column6 LIKE '{5}'", txtName.Text, txtSollSt.Text, txtColumn3.Text, txtColumn4.Text, txtColumn5.Text)

This code return an Error, "cannot perform 'like' operation on system.int32 and system.string". I have replaced the 'LIKE' with '='for the Number fileds, but the error still appears.
I want to ask, if it is possible to filter of all the fileds such as in Excel for example?
Can any one help me please.
 

The RowFilter property is set up like a WHERE clause in SQL. That means you put strings between single quotes, and you use no quotes for numeric data types. Use "={2}" (for example), for the integer fields.

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!
 
Extending jebenson's suggestion, you may consider logic like this:

Code:
Dim str As String = "1 + 1 = 2"

If Strings.Trim(txtName.TextLength) > 0 Then
    str &= " AND Name LIKE '*" & txtName.Text & "*', "
End If

If Strings.Trim(txtSollSt.TextLength) > 0 Then
    str &= " AND SollStd LIKE '*" & txtSollSt.Text & "*'"
End If

...

tvw.RowFilter = str

Have fun.

---- Andy
 
Thanks alot for the help.
I'm very happy that the problem solved.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top