borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2012 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Sql with Visual basic kindly help)Next Topic (Data Type Mismatch - What does it mean..??) New Topic New Poll Post Reply
AndreaVB Forum : Database : Recordset "LIKE" filter of a number column
Poster Message
menny
Level: Protégé

Registered: 02-12-2004
Posts: 5

icon Recordset "LIKE" filter of a number column

Hello,
i'm trying to do a LIKE filter to a numeric column.
the idea is that i could make a LIKE filter just as i would on a varchar column.

any ideas?

02-12-2004 at 08:21 AM
View Profile Send Email to User Show All Posts | Quote Reply
b marshall
Level: Graduate

Registered: 28-10-2004
Posts: 11
icon Re: Recordset "LIKE" filter of a number column

Did you try using % as part of your LIKE filter?  For example, if you wanted all numbers that begin with a 12 then you would enter something like the following:

SELECT ....... FROM .........WHERE ...... LIKE '12%'



If that doesnt answer your question then please explain in more detail...

02-12-2004 at 02:29 PM
View Profile Send Email to User Show All Posts | Quote Reply
menny
Level: Protégé

Registered: 02-12-2004
Posts: 5
icon Re: Recordset "LIKE" filter of a number column

I'll explain in details.

i want to use ADO Recordset's Filter property to remove unwanted rows from the recordset.

I want to do it in the recordset (in RAM) and not to re-query the SQL server.

The Recordset object has a property called "Filter" which gives a quick way to filter the rows.

but this property is not 100% SQL. therefore, it does not support LIKE statement for numeric columns.

i'm looking for a way to do it anyway (maybe some mathematical way....)

btw, the simple LIKE statement with % or * does not work.

thanks.

02-12-2004 at 03:09 PM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1137
icon Re: Recordset "LIKE" filter of a number column

Try this

rs.filter = "fieldname like 'SW%'"

It worked on my pc


Steve  

02-12-2004 at 05:11 PM
View Profile Send Email to User Show All Posts | Quote Reply
menny
Level: Protégé

Registered: 02-12-2004
Posts: 5
icon Re: Recordset "LIKE" filter of a number column

Hi.
your code did not work for me.

does your "fieldname" column is a numeric column?

in my table, the column is a "int" type.
therefore, "LIKE" is not posible on it.

i'm looking for a trick or something that will allow me to do it or simulate it.

thanks

05-12-2004 at 12:10 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 776
icon Re: Recordset "LIKE" filter of a number column

Some tries I'd do:
rs.filter = "fieldname LIKE " & CStr(12)
rs.filter = "fieldname LIKE " & Chr(34) & CStr(12) & Chr(34)

rs.filter = "fieldname LIKE " & Chr(Asc("1")) & Chr(Asc("2"))
rs.filter = "fieldname LIKE " & Chr(34) & Chr(Asc("1")) & Chr(Asc("2")) & Chr(34)

Hope one could match.


____________________________
Real Programmer can count up to 1024 on his fingers

05-12-2004 at 01:20 PM
View Profile Send Email to User Show All Posts | Quote Reply
menny
Level: Protégé

Registered: 02-12-2004
Posts: 5
icon Re: Recordset "LIKE" filter of a number column

Hi yronium,
What version of VB have you tried it on?
i'm using VB6 SP5.
Does the column "fieldname" (in your tests) is a numeric column (int,lomg, etc) ?

05-12-2004 at 01:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 776
icon Re: Recordset "LIKE" filter of a number column

I didn't try it, "I'd do" was meaning "I would do".
I use VB6 SP5 too, for what it matters.

I would do these attempt in order to retrieve the string value even from a stored number. I don't have a column named "fieldname": I just reported the name of the previous post. But I would try to convert the numeric value in my field into a string. So try it: if it works (I hope at least one does), it does even on numeric columns.

Let us know.

____________________________
Real Programmer can count up to 1024 on his fingers

06-12-2004 at 12:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
menny
Level: Protégé

Registered: 02-12-2004
Posts: 5
icon Re: Recordset "LIKE" filter of a number column

Hi.
i've tried the code you suggested.
all four does not work.
the ones without the ' char does not  cause error, but also does not filter.

any other ideas? i'll gladly try more

thanks

06-12-2004 at 07:41 AM
View Profile Send Email to User Show All Posts | Quote Reply
steve_w
Level: Moderator


Registered: 18-04-2003
Posts: 1137
icon Re: Recordset "LIKE" filter of a number column

Hi

What version of ado are you using, and can you please post your code here?

Steve  

06-12-2004 at 10:07 AM
View Profile Send Email to User Show All Posts | Quote Reply
BON
Level: Trainee

Registered: 12-08-2009
Posts: 1
icon Re: Recordset "LIKE" filter of a number column

hi try this it may help
its for vb6

retrieve the data and convert it to string
then use the like "%" statement


dim phone as string
phone=text1.text
'whether the data in text1 is numeric or char
'all is handled as string
datacontrol.comandtype=adcmdtext
dtacontrol.recordsource="select_from _ where _ like'"+phone+"%'"
datacontrol.refresh

ben


____________________________
Its all possible

12-08-2009 at 02:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Database : Recordset "LIKE" filter of a number column
Previous Topic (Sql with Visual basic kindly help)Next Topic (Data Type Mismatch - What does it mean..??) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2012 Andrea Tincaniborder