Filters with Dataview or new SELECT

  • Thread starter Thread starter Masahiro Ito
  • Start date Start date
M

Masahiro Ito

I am new to database programming, and would like to follow the preferred
programming methods when possible...

I have large databases, in a small 'always connected' environment. I have
been pulling large tables, and creating filters with some checkboxes etc..,
which create dataviews. Couple of questions:

1. Is there an easier way to create the filters than a bunch of IF THEN's
to create the filter string? (ie: if first filter add "(", if last add
")", if not first or last add " or ")...

2. Can I use the Compute command on dataviews?

3. I have been creating some classes to help with the 'logic' of analysis
on some of the data. It appears to me that developers choose between
either using the DataAdapters, Datasets and bound data direct from the
database for their forms, or they create class objects, and bind the
classes to the datasources. It would appear that classes would be the
safest, but more complex route. The VB books that I have spend good energy
on classes, and then good energy on ADO, but always seem to separate ADO
from classes (ie: run through all the standard dataadapter/dataset bound
directly to the forms components). I am currently enjoying the Deitel
VB.NET book, which I highly recommend to beginning programmers - but it
will take me some time to get through it.

Looking forward to any comments.

Masa
 
Hi,

Masahiro Ito said:
I am new to database programming, and would like to follow the preferred
programming methods when possible...

I have large databases, in a small 'always connected' environment. I have
been pulling large tables, and creating filters with some checkboxes etc..,
which create dataviews. Couple of questions:

1. Is there an easier way to create the filters than a bunch of IF THEN's
to create the filter string? (ie: if first filter add "(", if last add
")", if not first or last add " or ")...
No.

2. Can I use the Compute command on dataviews?
No.

3. I have been creating some classes to help with the 'logic' of analysis
on some of the data. It appears to me that developers choose between
either using the DataAdapters, Datasets and bound data direct from the
database for their forms, or they create class objects, and bind the
classes to the datasources. It would appear that classes would be the
safest, but more complex route. The VB books that I have spend good energy
on classes, and then good energy on ADO, but always seem to separate ADO
from classes (ie: run through all the standard dataadapter/dataset bound
directly to the forms components). I am currently enjoying the Deitel
VB.NET book, which I highly recommend to beginning programmers - but it
will take me some time to get through it.

I guess you are mixing some terms.
There are basically only two ways how you retrieve data:
One is using a DataReader type class (forward only readonly cursor) while
the other is to use DataAdapter type class to Fill the DataTables (which
might reside in a dataset).
There is certainly no more binding to database anymore.
Using DataSets/DataTables is the easiest way...
 
Miha Markic said:
I guess you are mixing some terms.
There are basically only two ways how you retrieve data:
One is using a DataReader type class (forward only readonly cursor)
while the other is to use DataAdapter type class to Fill the
DataTables (which might reside in a dataset).
There is certainly no more binding to database anymore.
Using DataSets/DataTables is the easiest way...

Thanks for your input Miha. When I do a filter, I like to summarize the
data that is has now been filtered, so I am going through the data in
loops doing calculations. Perhaps it would be best to repopulate the
dataset/datatables with a new SELECT command, but I have had trouble with
clearing datasets/datarelations to 'start new' with an already loaded
form. I guess I should revisit this again...

What I meant by my last question was that I could build a class with
rules etc, and load the data through methods of the class. For example,
I could have a Customer class, with the methods of the class populating
the properties of the customer from the database (using datareader
probably). I would likely also have a Customers class as collection of
my customer instances. I think I understand this in theory, but the
books and tutorials seem to spend their energy on the dataset/binding,
whereas my management is pushing the class object based style.

Masa
 
Hi Masahiro
Thanks for your input Miha. When I do a filter, I like to summarize the
data that is has now been filtered, so I am going through the data in
loops doing calculations.

You might use DataTable.Compute method instead - it accepts a filter
expression as parameter.

Perhaps it would be best to repopulate the
dataset/datatables with a new SELECT command, but I have had trouble with
clearing datasets/datarelations to 'start new' with an already loaded
form. I guess I should revisit this again...

You might set dataset.EnableConstraints = false, do repopulate and at the
end re-enable constraints.
Or, you might just invoke dataset.Clear() to clear all rows.
If you want provide more details on your problem so we can assist you
better.
What I meant by my last question was that I could build a class with
rules etc, and load the data through methods of the class. For example,
I could have a Customer class, with the methods of the class populating
the properties of the customer from the database (using datareader
probably). I would likely also have a Customers class as collection of
my customer instances. I think I understand this in theory, but the
books and tutorials seem to spend their energy on the dataset/binding,
whereas my management is pushing the class object based style.

I don't think you need this only for computing values - it is more coding,
slower, takes more resources..
 
Back
Top