Re: Better way? (DataView question)



Thanks for your reply! I tried this but it doesn't error and doesn't filter
out any records:

strSQL = "StoredProcHere"

Dim objCommand As New SqlCommand(strSQL, objConnection)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(strSQL, objConnection)

da.Fill(ds, "Collections")

Dim dv As New DataView(ds.Tables("Collections"))
dv.RowFilter = "Collection_Period = 'Active'"
dgCollections.DataSource = dv.Table
dgCollections.DataBind()

....does this not work with Stored Procedures?

"Peter Bromberg [C# MVP]" <pbromberg@xxxxxxxxxxxxxxxxxxx> wrote in message
news:184E922F-31BD-4BFD-B84B-5325E0999308@xxxxxxxxxxxxxxxx
James,
Why don't you try dispensing with the creation of the dataTable, and just
set the filter property on the DataSource which will give you a DataView
consisting of the matching records. Each DataTable has a DefaultView. You
can
set the filter and sort properties on this, and bind directly to the
result.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"James" wrote:

Basically I have a DataGrid that I'm binding to the results of a stored
procedure call. The recordset is fairly small. Initially I'm creating a
DataSet from the results and binding it. There's a DropDownList on my
page
that filters the records that are displayed in the grid.

How I'm currently handling this is when I initially bind, I create a
DataView from the table in the dataset. When the DropDownList changes
selection, I get the DataView from the Session variable (all of the
original
data) and I create a DataTable that's a copy of the table within the
dataview. Then I loop through each DataRow in the DataTable and do
dr.Delete() on the records that don't meet the criteria, and rebind to
the
DataTable. This seems really hokey. Is there a better way to do this
without having to jump through all of these hoops just to filter a
dataset?

The reason I create the DataTable as a copy is because if I delete the
records from the DataView, it seems to affect the original dataset, which
I'm trying to keep intact.

::confused::

Thanks





.



Relevant Pages

  • Re: Nasty DataView bug
    ... without the filter, so it should remain the same. ... Filter a DataView ... >> Dim oTable As DataTable ... >> Dim oView As DataView ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Separating 1 workbook into multiple workbooks
    ... It will filter on column A this example ... I assume that your headers are in row 1 so the header "Supervisor" is in A1 ... Dim CalcMode As Long ... 'Name of the sheet with your data ...
    (microsoft.public.excel.misc)
  • Re: Separating 1 workbook into multiple workbooks
    ... It will filter on column A this example ... I assume that your headers are in row 1 so the header "Supervisor" is in A1 ... Dim CalcMode As Long ... 'Name of the sheet with your data ...
    (microsoft.public.excel.misc)
  • Re: Separating 1 workbook into multiple workbooks
    ... It will filter on column A this example ... I assume that your headers are in row 1 so the header "Supervisor" is in A1 ... Dim CalcMode As Long ... 'Name of the sheet with your data ...
    (microsoft.public.excel.misc)
  • RE: Set Filter from Startup form to another form
    ... Private Sub Form_Load ... Dim strPrg As String ... Private Function StartProgramAs String ... Now all that is necessary is to set the filter for each form where you want ...
    (microsoft.public.access.formscoding)