472,796 Members | 1,381 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

FindRows in DataView - Not searching some columns

I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.

Dim objKeys(2) as Object

objKeys(0) = "CL"
objKeys(2) = 4000

Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView.FindRows(objKeys)

What I am trying to do is keep a filtered dataset (filter will not
change often) and subfilter on it.

I don't want to go through every row in the dataview and then compare
the columns with the subfilter criteria as I assume that this would be
much slower.
Thanks.

Dave.
Nov 20 '05 #1
5 8722
http://www.knowdotnet.com/articles/adopartiii.html

--
W.G. Ryan MVP Windows - Embedded

http://forums.devbuzz.com
http://www.knowdotnet.com/dataaccess.html
http://www.msmvps.com/williamryan/
"David Wender" <da**********@yahoo.com> wrote in message
news:cb**************************@posting.google.c om...
I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.

Dim objKeys(2) as Object

objKeys(0) = "CL"
objKeys(2) = 4000

Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView.FindRows(objKeys)

What I am trying to do is keep a filtered dataset (filter will not
change often) and subfilter on it.

I don't want to go through every row in the dataview and then compare
the columns with the subfilter criteria as I assume that this would be
much slower.
Thanks.

Dave.

Nov 20 '05 #2
David,
Have you considered using two DataViews?

Remember that a single DataTable can have any number of DataView objects
associated with it.
Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows) Dim posView2 As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract", _
DataViewRowState.CurrentRows) Dim foundRows() As DataRowView = posView2.FindRows(objKeys)
Of course multiple DataViews on a DataTable can cause performance problems,
however if the sort keys are the same, I understand that the underlying
index is shared among the Views, I'm not sure what would happen in this
case...

Hope this helps
Jay

"David Wender" <da**********@yahoo.com> wrote in message
news:cb**************************@posting.google.c om... I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.

Dim objKeys(2) as Object

objKeys(0) = "CL"
objKeys(2) = 4000

Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView.FindRows(objKeys)

What I am trying to do is keep a filtered dataset (filter will not
change often) and subfilter on it.

I don't want to go through every row in the dataview and then compare
the columns with the subfilter criteria as I assume that this would be
much slower.
Thanks.

Dave.

Nov 20 '05 #3
Hi Jay,
Thanks for the reply. I hadn't thought of using a second dataview on
the same table. However in this case I'm not sure it would be
appropriate. Here's some background of what I'm trying to get done.

1) I start with a large DataSet - it includes all data for a given
Group of Traders.

2) Within this large group of data, a user will typically only want to
see a particular subset most of the time. (i.e. they may want to see
all Crude Oil, Heating Oil and Gasoline trades done by traders Dave
and Mike) Therefore I rebuild this special dataview only when the user
wants to switch to a different subgroup. Hopefully this saves
resources since I rarely need to change the sort order or filter of
the dataview. Also the custom filters can get a little complex so I
don't really want to build them often.

3) Though this subgroup filter does not change often, I need to
calculate values of subsets of this data every few seconds. For
example, if a new Heating Oil price comes in, I want to recalculate
all of the Heating Oil prices in the dataview - hence the need to
filter the dataview.

4) Though I usuallly will only need to search on one column, I need
the view sorted on another column because of certain calculations that
are made only when that column changes.

Thanks again and appreciate your help.

Dave.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<eR**************@TK2MSFTNGP12.phx.gbl>...
David,
Have you considered using two DataViews?

Remember that a single DataTable can have any number of DataView objects
associated with it.
Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim posView2 As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView2.FindRows(objKeys)


Of course multiple DataViews on a DataTable can cause performance problems,
however if the sort keys are the same, I understand that the underlying
index is shared among the Views, I'm not sure what would happen in this
case...

Hope this helps
Jay

"David Wender" <da**********@yahoo.com> wrote in message
news:cb**************************@posting.google.c om...
I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.

Dim objKeys(2) as Object

objKeys(0) = "CL"
objKeys(2) = 4000

Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView.FindRows(objKeys)

What I am trying to do is keep a filtered dataset (filter will not
change often) and subfilter on it.

I don't want to go through every row in the dataview and then compare
the columns with the subfilter criteria as I assume that this would be
much slower.
Thanks.

Dave.

Nov 20 '05 #4
David,
1) I start with a large DataSet - it includes all data for a given
Group of Traders. Sounds good.
2) Within this large group of data, a user will typically only want to
the dataview. Also the custom filters can get a little complex so I
don't really want to build them often. You can pass the same filter to both DataViews.
3) Though this subgroup filter does not change often, I need to
calculate values of subsets of this data every few seconds. Changing rows in the DataSet will change rows in all of the DataViews.
hence the need to filter the dataview. Are you processing the Dataview itself? Have you considered using
DataTable.Select instead?
4) Though I usuallly will only need to search on one column, I need
the view sorted on another column because of certain calculations that
are made only when that column changes. If you are using the View for processing you may want to consider using
DataTable.Select instead. If you are using it for Display then the DataView
is the way to go. Depending on what you are doing I would use both!

Const format As String = "Trader='{0}' And Commodity='{1}' And
Contact={2}"
Dim table As DataTable = posDS.Tables("Positions")
Dim filter As String = String.Format(format, "Dave", "CL", 4000)
Dim sort As String = "Commodity, Contract, Strike"
Dim foundRows() As DataRow = table.Select(filter, sort,
DataViewRowState.CurrentRows)

Note you get back an array of DataRow objects, not an array of DataRowView
objects.

Hope this helps
Jay

"David Wender" <da**********@yahoo.com> wrote in message
news:cb**************************@posting.google.c om... Hi Jay,
Thanks for the reply. I hadn't thought of using a second dataview on
the same table. However in this case I'm not sure it would be
appropriate. Here's some background of what I'm trying to get done.

1) I start with a large DataSet - it includes all data for a given
Group of Traders.

2) Within this large group of data, a user will typically only want to
see a particular subset most of the time. (i.e. they may want to see
all Crude Oil, Heating Oil and Gasoline trades done by traders Dave
and Mike) Therefore I rebuild this special dataview only when the user
wants to switch to a different subgroup. Hopefully this saves
resources since I rarely need to change the sort order or filter of
the dataview. Also the custom filters can get a little complex so I
don't really want to build them often.

3) Though this subgroup filter does not change often, I need to
calculate values of subsets of this data every few seconds. For
example, if a new Heating Oil price comes in, I want to recalculate
all of the Heating Oil prices in the dataview - hence the need to
filter the dataview.

4) Though I usuallly will only need to search on one column, I need
the view sorted on another column because of certain calculations that
are made only when that column changes.

Thanks again and appreciate your help.

Dave.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message

news:<eR**************@TK2MSFTNGP12.phx.gbl>...
David,
Have you considered using two DataViews?

Remember that a single DataTable can have any number of DataView objects
associated with it.
Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim posView2 As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView2.FindRows(objKeys)


Of course multiple DataViews on a DataTable can cause performance problems, however if the sort keys are the same, I understand that the underlying
index is shared among the Views, I'm not sure what would happen in this
case...

Hope this helps
Jay

"David Wender" <da**********@yahoo.com> wrote in message
news:cb**************************@posting.google.c om...
I want to create a dataview with a sort on multiple columns. However,
when I use FindRows, I only want to search some of the columns, not
all. Is this possible? I have not been able to make it happen.

Dim objKeys(2) as Object

objKeys(0) = "CL"
objKeys(2) = 4000

Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
"Trader = 'Dave'", "Commodity, Contract, Strike", _
DataViewRowState.CurrentRows)

Dim foundRows() As DataRowView = posView.FindRows(objKeys)

What I am trying to do is keep a filtered dataset (filter will not
change often) and subfilter on it.

I don't want to go through every row in the dataview and then compare
the columns with the subfilter criteria as I assume that this would be
much slower.
Thanks.

Dave.

Nov 20 '05 #5
Hi Jay,

Thanks again for your help, I really appreciate it.
I never realized that you could apply a sort on a datatable.select,
that's a nice trick!
Anyway, I think I am going to stick with processing the dataview
simply because it doesn't change often and therefore doing a select
every few seconds would probably add unnecessary overhead. Basically
what happens is that if a futures price changes, I need to recalculate
theoretical position values that derive from the positions in the
dataview. The positions in the dataview don't change much, it's just
that I need to do calculations based on new values that are not in the
table/view.

It would be interesting to see if anyone has done any performance
tests regarding the datatable.select command on tables with and
without primary keys, and on dataviews.

Dave.

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<#E**************@TK2MSFTNGP10.phx.gbl>...
David,
1) I start with a large DataSet - it includes all data for a given
Group of Traders.

Sounds good.
2) Within this large group of data, a user will typically only want to
the dataview. Also the custom filters can get a little complex so I
don't really want to build them often.

You can pass the same filter to both DataViews.
3) Though this subgroup filter does not change often, I need to
calculate values of subsets of this data every few seconds.

Changing rows in the DataSet will change rows in all of the DataViews.
hence the need to filter the dataview.

Are you processing the Dataview itself? Have you considered using
DataTable.Select instead?
4) Though I usuallly will only need to search on one column, I need
the view sorted on another column because of certain calculations that
are made only when that column changes.

If you are using the View for processing you may want to consider using
DataTable.Select instead. If you are using it for Display then the DataView
is the way to go. Depending on what you are doing I would use both!

Const format As String = "Trader='{0}' And Commodity='{1}' And
Contact={2}"
Dim table As DataTable = posDS.Tables("Positions")
Dim filter As String = String.Format(format, "Dave", "CL", 4000)
Dim sort As String = "Commodity, Contract, Strike"
Dim foundRows() As DataRow = table.Select(filter, sort,
DataViewRowState.CurrentRows)

Note you get back an array of DataRow objects, not an array of DataRowView
objects.

Hope this helps
Jay

Nov 20 '05 #6

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

Similar topics

4
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected...
1
by: Phil Townsend | last post by:
I have a dataview that is generated from a dataset which gets its data from an xml file. I would like to use the dataview to include only certain columns in the result set. The xml file contains 7...
8
by: Dave Hagerich | last post by:
I'm using a DataGrid with a DataSet and I'm trying to filter the data being displayed, using the following code as a test: DataView theView = new DataView(theDataSet.Tables); theView.RowFilter =...
1
by: Able | last post by:
Dear friends Two of the columns in the table tblAdressbook is the field "FirstName" and the field "personID". The table is loaded in the dataset myDataset and is sorted by "personID" in the...
2
by: RSH | last post by:
I have a situation where I am filling two datasets and I need to print out the names that appear in both datasets. I initially converted them to dataviews, sorted on last name and performed a...
4
by: Niki | last post by:
I'm using findrows to extract specific rows from a dataview, and then want to bind to them. I'd assumed that you bound to the array result as you would to the the dataview, but the system can't...
0
by: Nathan Franklin | last post by:
Hello Guys, I have been trying to work this our for so long, but I just can't seem to find the answer. I am loading a datatable from a an access database using an oledbdataadapter. I then...
0
by: Rami Prilutsky | last post by:
I'm binding the dataView to a dataset (~400000 rows) and sorting it by a key (long type). I'm retrieving values from the DataView with FindRows(object key) which returns DataRowView. The...
0
by: Michael_R_Banks | last post by:
I have a table ("checkout") that I'm tracking equipment checkout transaction. It has columns: checkoutid (key), checkedbyid, checkedtoid, dateout, datein and inventoryid. When the user scans an...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.