Link to home
Create AccountLog in
Avatar of JeepGeekin
JeepGeekin

asked on

Filter with Functions

I have a date column that I want to apply a filter to (using the dataview rowfilter). My problem is that I need to filter it by just the Year of that column, not the whole date.

Something like this is what I am currently working with:
        Dim dv As New DataView(ds.Tables(0))
        dv.RowFilter = "Year(payment_date) = " & text1.text.trim
        GridView1.DataSource = dv
        GridView1.DataBind()

This gives me the error:  The expression contains undefined function call Year().
Is there a way to do this without altering the dataset possibly using date functions?
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

You could add an additional column to your query and then filter on that.

"SELECT ..., Year(payment_date) as payment_year, ... FROM ..."

dim dv as new dataview(ds.tables(0))
dv.rowfilter = "payment_year = " + text1.text.trim

you will probalby want to add datagridcolumns to your gridview so that the payment_year isn't included.
ASKER CERTIFIED SOLUTION
Avatar of Sancler
Sancler

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of JeepGeekin
JeepGeekin

ASKER

Great idea! Thanks! Worked perfectly.

...also, thanks BriCrow, but I was asked to avoid altering the sql since multiple people use it.