Groups | Blog | Home
all groups > dotnet ado.net > june 2005 >

dotnet ado.net : Applying Filter


Timo
6/30/2005 12:00:00 AM
I had tried something like that already, but I get an error:

Dim DV As DataView
DV = objdsWebvisitors.Tables("VISITOR").DefaultView
DV.RowFilter = "lastname like 'J%'"

'// replaced this auto-generated line
'// grdWEBVISITOR.SetDataBinding(objdsWebvisitors, "VISITOR")

'// with this line:

grdWEBVISITOR.SetDataBinding(DV, "VISITOR")


The error is:

"Cannot create a child list for field VISITOR".

The .SetDataBinding method expects a string as the second argument. When the
first argument is a DataSet, the second argument is the name of the table.
But if the first argument is a DataView, what should the second argument be?

Thanks
Timo

[quoted text, click to view]

Elton W
6/30/2005 6:18:03 AM
Hi Timo,

If you want to apply the filter to DB query, sql query is like

SELECT * FROM VISITOR WHERE lastname LIKE ‘J%’

If you get whole data into a datatable then apply the filter, you can use
following code:

Dim dv As DataView = datatable.DefaultView
dv.RowFilter = “lastname LIKE ‘J%’”

HTH

Elton Wang
elton_Wang@hotmail.com

[quoted text, click to view]
Timo
6/30/2005 8:13:05 AM
I have to build dozens of simple data-entry forms in just a couple of days,
and while I'm looking for a 3rd party tool that will help me do this, I
tried the Data Form Wizard in Visual Studio, which builds a persistent
dataset object based on a chosen table or view, and produces some basic
code-behind. The generated routine listed below binds the dataset member
(here, the VISITOR table) to a grid on the form.

How and where can I modify this code to apply a filter to the VISITOR table,
e.g. all visitors whose lastname begins with the letter 'J', so that only
the J-names are shown in the grid?
Thanks
Timo

'// generated by the Data Form wizard
Public Sub LoadDataSet()

Dim objDataSetTemp As FormsWizardTest.dsvisitors
objDataSetTemp = New FormsWizardTest.dsvisitors
Try

Me.FillDataSet(objDataSetTemp)


Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try


Try
grdVISITOR.DataSource = Nothing

objdsvisitors.Clear()

objdsvisitors.Merge(objDataSetTemp)
grdVISITOR.SetDataBinding(objdsvisitors, "VISITOR")

grdVISITOR.

Catch eLoadMerge As System.Exception

Throw eLoadMerge
End Try

End Sub


Bud Dean
6/30/2005 8:27:56 AM
Timo:

apply your filter in this area:

grdVISITOR.SetDataBinding(objdsvisitors, "VISITOR")

Create a dataview and aply the rowfilter. Then set the datasource of the
datgrid to the dataview, like Elton's example..

HTH,

bud
[quoted text, click to view]

Timo
6/30/2005 9:41:59 AM
Thanks, Elton. It isn't the syntax of how to create a filter that I need
help with, but where, *in the code generated by the Data Form Wizard*, the
filter should be applied, so that the grid on the form displays the matching
rows. When I apply the filter it is having no effect on the grid.
Regards
Timo


[quoted text, click to view]

Timo
6/30/2005 2:07:52 PM
I found out the answer-- second argument can be String.Empty
Thanks for the help.
Timo

AddThis Social Bookmark Button