Filtering DataSet Question

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

Hi,

I have two question regarding retrieving results from a DataSet. First,
what is the best way to retrieve results from a dataset with a filter?
Right now I am using the DataView class. I also have a question regarding
the DataView class. Using the code below how do I cast the data returned by
the code below into a bool.

DataView modelDataView = new
DataView(base.componentDataSet.Tables["tblModels"]);
modelDataView.Sort = "strCode";
int index = modelDataView.Find(modelCode);
v = modelDataView[index]["blnV"];
f = modelDataView[index]["blnF"];

Thanks
 
Mike said:
Hi,

I have two question regarding retrieving results from a DataSet. First,
what is the best way to retrieve results from a dataset with a filter?

Add a WHERE clause to your SQL statement. eg:

SELECT * FROM myTable WHERE someField = someValue
Right now I am using the DataView class. I also have a question regarding
the DataView class. Using the code below how do I cast the data returned by
the code below into a bool.

DataView modelDataView = new
DataView(base.componentDataSet.Tables["tblModels"]);
modelDataView.Sort = "strCode";
int index = modelDataView.Find(modelCode);
v = modelDataView[index]["blnV"];
f = modelDataView[index]["blnF"];

Thanks

assuming v is declared as a bool

v = (bool) modelDataView[index]["blnV"];

should work if the value was actually sorted as a boolean in the database,
otherwise the value in the database is actually a string you could try:

v = (modelDataView[index]["blnF"] == "TrueValue");

where TrueValue is whatever you are interpreting as true (eg, True, 1, yes,
.....)
 
Thanks for your post. I am still curious which way is better to retrieve
results from a dataset. Using the select statement or a dataview?

Thanks

Matt Burland said:
Mike said:
Hi,

I have two question regarding retrieving results from a DataSet. First,
what is the best way to retrieve results from a dataset with a filter?

Add a WHERE clause to your SQL statement. eg:

SELECT * FROM myTable WHERE someField = someValue
Right now I am using the DataView class. I also have a question regarding
the DataView class. Using the code below how do I cast the data
returned
by
the code below into a bool.

DataView modelDataView = new
DataView(base.componentDataSet.Tables["tblModels"]);
modelDataView.Sort = "strCode";
int index = modelDataView.Find(modelCode);
v = modelDataView[index]["blnV"];
f = modelDataView[index]["blnF"];

Thanks

assuming v is declared as a bool

v = (bool) modelDataView[index]["blnV"];

should work if the value was actually sorted as a boolean in the database,
otherwise the value in the database is actually a string you could try:

v = (modelDataView[index]["blnF"] == "TrueValue");

where TrueValue is whatever you are interpreting as true (eg, True, 1, yes,
 
Hi Mike,

When you just want to view Rows from a single table you can also use the
Select method of the Table and pass a filterExpression. About your second
question i'am not sure what you want but the indexer of the DataView returns
a DataRowView of which you use another indexer to get back a object which
you can cast so v = (bool)DataView[index][columnName]. If you not sure of
the returned type you can examine the DataType of the DataColumn who's name
your using.

Robert
 
It kind of depends. If you want to apply one and only one filter to your
data and you know you are never going to want the data that's getting
filtered out, then using the SELECT statement is the way to go because
you'll have less data to transfer from your data source and less data to
hold in memory. However, if you want to be able to filter you data, then
remove the filter and see all the data, then apply a different filter, you
are probably better off getting all your data and then applying the filters
thru a dataview. This will reduce the number of trips to your datasource.
Although again, it depends how much data you have and how often you think
you'll need to filter it.

Mike said:
Thanks for your post. I am still curious which way is better to retrieve
results from a dataset. Using the select statement or a dataview?

Thanks

Matt Burland said:
Mike said:
Hi,

I have two question regarding retrieving results from a DataSet. First,
what is the best way to retrieve results from a dataset with a filter?

Add a WHERE clause to your SQL statement. eg:

SELECT * FROM myTable WHERE someField = someValue
Right now I am using the DataView class. I also have a question regarding
the DataView class. Using the code below how do I cast the data
returned
by
the code below into a bool.

DataView modelDataView = new
DataView(base.componentDataSet.Tables["tblModels"]);
modelDataView.Sort = "strCode";
int index = modelDataView.Find(modelCode);
v = modelDataView[index]["blnV"];
f = modelDataView[index]["blnF"];

Thanks

assuming v is declared as a bool

v = (bool) modelDataView[index]["blnV"];

should work if the value was actually sorted as a boolean in the database,
otherwise the value in the database is actually a string you could try:

v = (modelDataView[index]["blnF"] == "TrueValue");

where TrueValue is whatever you are interpreting as true (eg, True, 1, yes,
 
Thanks for your post. I am still curious which way is better to retrieve
results from a dataset. Using the select statement or a dataview?

It depends somewhat on your situation, but know that using the select
statement all the filtering is done in the database server and only the
filtered records are transferred to the client.

Using a dataview means that all the records are brought to the client
and then filtered there.

So, generally speaking, I use the select statement because it reduces
traffic between the client and the (database) server and it reduces the
client requirements (memory, etc).

On the other hand, if you wanted to make several different queries
against the data and your (database) server was swamped with other
business, perhaps you might want to bring over a large dataset and
filter locally.

But almost always you're better off doing the database work on the
database server.

-- Rick
 
Thanks for your post. This what I am doing. When the form is loaded I go
out and retrieve data specific to each combo box via a stored procedures and
then load it into a dataset for each combo box. I also retrieve all the
data in the tables that will be specific to each user selection. Instead of
going back to the database to retrieve this data I have designed that each
combo box dataset is merged to one large dataset which is then persisted to
an xml file. Each combo box is represented in a class heirarchy as each is
dervided from a base class which holds the large dataset. I decided to
design it this way without having 8 different xml files for each dataset. I
have wrestled with either having one large dataset or having 8 different
datasets. So, with that in mind is the SELECT statement the way to go?

Thanks

Matt Burland said:
It kind of depends. If you want to apply one and only one filter to your
data and you know you are never going to want the data that's getting
filtered out, then using the SELECT statement is the way to go because
you'll have less data to transfer from your data source and less data to
hold in memory. However, if you want to be able to filter you data, then
remove the filter and see all the data, then apply a different filter, you
are probably better off getting all your data and then applying the filters
thru a dataview. This will reduce the number of trips to your datasource.
Although again, it depends how much data you have and how often you think
you'll need to filter it.

Mike said:
Thanks for your post. I am still curious which way is better to retrieve
results from a dataset. Using the select statement or a dataview?

Thanks

Matt Burland said:
Hi,

I have two question regarding retrieving results from a DataSet. First,
what is the best way to retrieve results from a dataset with a filter?

Add a WHERE clause to your SQL statement. eg:

SELECT * FROM myTable WHERE someField = someValue

Right now I am using the DataView class. I also have a question regarding
the DataView class. Using the code below how do I cast the data returned
by
the code below into a bool.

DataView modelDataView = new
DataView(base.componentDataSet.Tables["tblModels"]);
modelDataView.Sort = "strCode";
int index = modelDataView.Find(modelCode);
v = modelDataView[index]["blnV"];
f = modelDataView[index]["blnF"];

Thanks

assuming v is declared as a bool

v = (bool) modelDataView[index]["blnV"];

should work if the value was actually sorted as a boolean in the database,
otherwise the value in the database is actually a string you could try:

v = (modelDataView[index]["blnF"] == "TrueValue");

where TrueValue is whatever you are interpreting as true (eg, True, 1, yes,
....)
 
Hi Mike,

Since you might use all the data in the table, retrieving all the data from
the database and use a DataView as a filter is a good idea. Because when
you fill the dataset for the first time, all the data are dumped to the
client side. And the filter operation can be done on the client side. This
might enhance the performance.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: "Mike" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: Filtering DataSet Question
| Date: Mon, 20 Oct 2003 13:50:00 -0600
| Lines: 92
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| NNTP-Posting-Host: 64.207.45.37
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64089
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Thanks for your post. This what I am doing. When the form is loaded I go
| out and retrieve data specific to each combo box via a stored procedures
and
| then load it into a dataset for each combo box. I also retrieve all the
| data in the tables that will be specific to each user selection. Instead
of
| going back to the database to retrieve this data I have designed that each
| combo box dataset is merged to one large dataset which is then persisted
to
| an xml file. Each combo box is represented in a class heirarchy as each
is
| dervided from a base class which holds the large dataset. I decided to
| design it this way without having 8 different xml files for each dataset.
I
| have wrestled with either having one large dataset or having 8 different
| datasets. So, with that in mind is the SELECT statement the way to go?
|
| Thanks
|
| | > It kind of depends. If you want to apply one and only one filter to your
| > data and you know you are never going to want the data that's getting
| > filtered out, then using the SELECT statement is the way to go because
| > you'll have less data to transfer from your data source and less data to
| > hold in memory. However, if you want to be able to filter you data, then
| > remove the filter and see all the data, then apply a different filter,
you
| > are probably better off getting all your data and then applying the
| filters
| > thru a dataview. This will reduce the number of trips to your
datasource.
| > Although again, it depends how much data you have and how often you
think
| > you'll need to filter it.
| >
| > | > > Thanks for your post. I am still curious which way is better to
| retrieve
| > > results from a dataset. Using the select statement or a dataview?
| > >
| > > Thanks
| > >
| > > | > > >
| > > > | > > > > Hi,
| > > > >
| > > > > I have two question regarding retrieving results from a DataSet.
| > First,
| > > > > what is the best way to retrieve results from a dataset with a
| filter?
| > > >
| > > > Add a WHERE clause to your SQL statement. eg:
| > > >
| > > > SELECT * FROM myTable WHERE someField = someValue
| > > >
| > > > > Right now I am using the DataView class. I also have a question
| > > regarding
| > > > > the DataView class. Using the code below how do I cast the data
| > > returned
| > > > by
| > > > > the code below into a bool.
| > > > >
| > > > > DataView modelDataView = new
| > > > > DataView(base.componentDataSet.Tables["tblModels"]);
| > > > > modelDataView.Sort = "strCode";
| > > > > int index = modelDataView.Find(modelCode);
| > > > > v = modelDataView[index]["blnV"];
| > > > > f = modelDataView[index]["blnF"];
| > > > >
| > > > > Thanks
| > > >
| > > > assuming v is declared as a bool
| > > >
| > > > v = (bool) modelDataView[index]["blnV"];
| > > >
| > > > should work if the value was actually sorted as a boolean in the
| > database,
| > > > otherwise the value in the database is actually a string you could
| try:
| > > >
| > > > v = (modelDataView[index]["blnF"] == "TrueValue");
| > > >
| > > > where TrueValue is whatever you are interpreting as true (eg, True,
1,
| > > yes,
| > > > ....)
| > > > >
| > > > >
| > > >
| > > >
| > >
| > >
| >
| >
|
|
|
 
v- said:
Since you might use all the data in the table, retrieving all the data from
the database and use a DataView as a filter is a good idea. Because when
you fill the dataset for the first time, all the data are dumped to the
client side. And the filter operation can be done on the client side. This
might enhance the performance.

What if the server is a 4-way Xeon with 4 GB of RAM and a 2 TB RAID 5
disk subsystem and the client is a PIII 500 MHz running Windows XP with
64 MB of memory.

Your reply is a little simplistic, isn't it?

-- Rick
 
Hi Rick,

You suggestion might be right on some senarios. However, few of us will
have a chance to develop on such a cool hardware system. So my last post
only covers general senarios.

Since mike is going to persist his dataset in an XML file on the client
side, I think maintaining one XML file might be more convenient that
dealing with eight. And even we have such good servers, if we are
retrieving data from a web service, the returned datasets might be
transfered through the internet. So we also need to consider the network
environment.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: Guinness Mann <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Subject: Re: Filtering DataSet Question
| Date: Tue, 21 Oct 2003 10:40:14 -0700
| Organization: Dublin Brewery
| Lines: 16
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| NNTP-Posting-Host: p-223.newsdawg.com
| X-Newsreader: MicroPlanet Gravity v2.60
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!newsfee
d01.sul.t-online.de!t-online.de!newspeer1-gui.server.ntli.net!ntli.net!peer0
1.cox.net!cox.net!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!enews4
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64174
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| In article <[email protected]>, v-
| (e-mail address removed) says...
| > Since you might use all the data in the table, retrieving all the data
from
| > the database and use a DataView as a filter is a good idea. Because
when
| > you fill the dataset for the first time, all the data are dumped to the
| > client side. And the filter operation can be done on the client side.
This
| > might enhance the performance.
|
| What if the server is a 4-way Xeon with 4 GB of RAM and a 2 TB RAID 5
| disk subsystem and the client is a PIII 500 MHz running Windows XP with
| 64 MB of memory.
|
| Your reply is a little simplistic, isn't it?
|
| -- Rick
|
|
 
v- said:
Since mike is going to persist his dataset in an XML file on the client
side, I think maintaining one XML file might be more convenient that
dealing with eight.

I agree with the part about having a single dataset/XML file (How's he
going to have permission to write to the disk on the client?), but as I
understood his question he was asking if he should bring the entire
database over to the client, or whether he should filter un-needed rows
at the server. I think in most cases the latter would be preferred.

But perhaps I misunderstood the question.

-- Rick
 
Yes, Rick. It all depends on how Mike is going to deal with the data
retrieved from the server. We're just providing him with our suggestions. :)

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| From: Guinness Mann <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Subject: Re: Filtering DataSet Question
| Date: Wed, 22 Oct 2003 14:30:02 -0700
| Organization: Dublin Brewery
| Lines: 15
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| NNTP-Posting-Host: p-478.newsdawg.com
| X-Newsreader: MicroPlanet Gravity v2.60
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-lei1.dfn.de!news-kar1.dfn.de!npeer.de.kpn-eurorings.net!news2.tele
byte.nl!logbridge.uoregon.edu!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy
.com!enews1
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:64339
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| In article <[email protected]>, v-
| (e-mail address removed) says...
| > Since mike is going to persist his dataset in an XML file on the client
| > side, I think maintaining one XML file might be more convenient that
| > dealing with eight.
|
| I agree with the part about having a single dataset/XML file (How's he
| going to have permission to write to the disk on the client?), but as I
| understood his question he was asking if he should bring the entire
| database over to the client, or whether he should filter un-needed rows
| at the server. I think in most cases the latter would be preferred.
|
| But perhaps I misunderstood the question.
|
| -- Rick
|
 
Back
Top