473,397 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Better way? (DataView question)

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
Apr 10 '06 #1
4 1565
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

Apr 10 '06 #2
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]" <pb*******@yahoo.nospammin.com> wrote in message
news:18**********************************@microsof t.com...
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

Apr 10 '06 #3
Aha! It seems to work when I set the datasource to just "dv" instead of
dv.Table. That's excellent. So should I just keep the DataSet in session
memory and then create a new DataView on SelectedIndexChanged form the
DataSet that's in session memory and create a filter? i.e.

InitialFunction()
Get Data In DataSet
Store Original DataSet in Session Memory
Bind to DataSet
End Function

On DropDownChange
Create DataView from DataSet in session memory
Create RowFilter
Bind to DataView
End Event

"James" <mi*******@gmail.com> wrote in message
news:u9**************@TK2MSFTNGP02.phx.gbl...
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]" <pb*******@yahoo.nospammin.com> wrote in message
news:18**********************************@microsof t.com...
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


Apr 10 '06 #4
See here:

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 Dataview =ds.Tables("Collections").DefaultView ' you can use
the default view if you want
dv.RowFilter = "Collection_Period = 'Active'"
dgCollections.DataSource = dv ' bind to the VIEW, not the table!
dgCollections.DataBind()
-- See the difference?
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"James" wrote:
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]" <pb*******@yahoo.nospammin.com> wrote in message
news:18**********************************@microsof t.com...
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


Apr 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Raymond Lewallen | last post by:
I have a dataview in which the sort property will not sort the dataview. Here's is a simple scenario similar to what I am doing: Class Foo Private Function Retrieve() As DataView ' Returns a...
4
by: Martin Schmid | last post by:
I am trying to implement a DataView for a DataGrid so I can sort at runtime by clicking on column headers. My initial page load works... it displays the data However, when I click a column...
6
by: Joe | last post by:
I have a DataView and would like to extract data from it and write it to a ListView. Can I only accomplish this with the DataViewRows Object array? Is there a way forme to enumerate through the...
3
by: Jonathan Allen | last post by:
What could cause a stack trace like this? Message:Object reference not set to an instance of an object. Stack Trace: at System.Data.DataView.GetRecord(Int32 recordIndex) at...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
14
by: Able | last post by:
Dear friends Dim myDataView as DataView = New DataView(dsData.Tables("tblCustomers")) myDataView.RowFilter = "City = 'London'" My question is how to loop through all rows in myDataView and...
8
by: KC | last post by:
For a DataView.Rowfilter can I use more than one expression? I want to filter out two different things. For example can I take: dv.RowFilter = "MTX <> 'Customer Forcast'" and ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.