Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


DataView Vs DataTable in vb.net - what to choose ?

Posted on 2004-04-25
Medium Priority
Last Modified: 2010-08-05
hi to all

i am new to vb.net.i need some help in binding the controls to the dataset in ado.net.

i want to attach comboboxes in my form with the through displaymember and valuemember properties to the tables.

suppose as a test case if i have 2 combos for dept,desig. when ever i select a particular dept then the desig combo should show only the designations in that dept dynamically.

i can't attach the original table directly as the rows in the original disig table changes dynamically ...

for this if i manually add these values dynamically through a datareader into these combos then settng the valuememeber values will be difficult (may not be possible).and these combos are not bound then the changes to the table will not be refreshed automatically.

At present i am creating one temporary table for each of these combos (here it requires 2 tables) and fill the data rows that match the crieteria through an adaptor.(not attaching the original tables)

its working fine. "but i am concerned about the performance and optimization of my application.

Is this approach is correct. or is it better to use views in place of tables.

"will it consume less memory than the tables cosume" ?.

Or is there any other way to achieve this task ?

any body please help me out.

thanx in adv.

Mohan G
Question by:gkmohan2003
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
LVL 27

Expert Comment

ID: 10913663
Hi gkmohan2003:
> Is this approach is correct.
In my opinion, binding is the technique to avoid.
It does not really matter if you use views or temporary tables, and unless the tables are gigantic, the memory consumed is not a matter of importance. In todays age where even an old fashioned system had MegaBytes of memory, the difference of a few KB is like a drop in the ocean, so not really something to worry about.

LVL 37

Assisted Solution

gregoryyoung earned 150 total points
ID: 10913919
>> Is this approach is correct.

umm  maybe ... There is alot more information needed. This is one way of doing this.

Another way would be to read all of your selections into a datatable and then use a dataview to provide the filterring (thus binding to the dataview). This is a classic problem in Computer Science, you either do the work up front, costing slightly more memory being used (but you can save it in between trips to the area) or you do the work on demand (you rebuild the table everytime) which is slower.

I find in both cases however that you are too tightly coupled to your datatable. I am assuming that these are often used values throughout your system. Based on this I bring up the idea of maintaining a logical structure of these within your application (through a class higherarchy). You can then bind this class higherarchy if you want. You can also encapsulate the ability to do "lazy" reading http://www.crazybob.org/roller/page/crazybob/20031224 has an example. Lazy reading allows you to do partial reads in attempt to provide the best of both worlds. You cache what you think is a reasonable amount of data occasionally throwing some away (so it will see updates and so it will not use up too much memory) but at the same time you will often hit memory instead of having to rebuild things (faster).

Here is an example of class higherarchy ...

public class A {
    public BParentDecoratorCollection BChildren ;
    //as info

public class BParentDecorator {
    public A Parent ;
    public B Child ;

public class B {
    //Bs info

then in my encapsulating class lets call it AManager I have a few methods ... One would be PreLoadAllAs() which would get all the As and populate all of the Bs keeping all info internal to the manager (it would be triggerred based upon a configuration point). I may also have a method GetA(someidentifier of the A) which would attempt a lazy read of that A (if its in the cache return, if not go create it, if not found exception). It is also very important that the manager be a singleton object. You only want 1 cache of these things for anyone calling :) ... I actually use this pattern alot in my applications as it allows you to determine at runtime whether it is better to have a small footprint or to be fast.

Also once you do this a few times you will realize that these "managers" with their caches look really similar. Surprisingly enough you can actually make a general purpose manager via the use of metadata (files, database, custom attributes etc) which will dynamically create various domain classes and populate them also allowing the use of a centralized cache ...

The first place I utilized this was for all of my lookup tables in a large system (700+ tables). It used a use frequency / last time based algorithm to figure out what it should keep vs what it shouldnt (naturally configurable at runtime). This is a great place to use something like this because whether or not you should keep lookup information in memory is a big deal in application performance.

I have always been of the opinion that in CS if you cant figure out which solution to a problem will work out better in the long run support both and be flexible. Your worst case scenario here is that you decide to store nothing in memory and end up with a cache hit before you go fetch the data everytime (nanoseconds in comparison with 200?? ms in hitting a database)

I understand that I have only given a very brief overview of this pattern here but it is a quite important one (most pattern books dedicate a chapter or more just to this concept). I would take a look in POSA for a great description ...http://www.awprofessional.com/title/0321127420

Hope this helps ya out in the long run ...
LVL 37

Expert Comment

ID: 10913934
I should add from just reading on the top that you are new to VB.Net ...

The info I gave you is not entry level stuff. It is meant mainly for the creation of large scale applications and reusable/maintainable code. If you are new to vb.net (and OOP in general) jumping into enterprise type development too quickly might make your head spin as you do many things which are almost counter intuitive to the easy answer because they hold alot of benefit in the future.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 10915687
thanks gregoryyoung ...
to let me know the way to develop entreprise level applications.

yea i am a new to vb.net (migrated from vb 6.0, it sucks a bit to go with vb.net at the beginning). yea as you said i can't jump into that level stuff.

But it may definitely help me in the long run ....
and i need to consider the memory size here. coz my DB (SQL server 2000) grows to 100 mb in 20 mnts.
probably this made me to choose these objects in a more cautious way...


Accepted Solution

redundguy earned 225 total points
ID: 10916297
I'm new in VB.NET but I have some experience in VB6. Now I'm learning VB.NET and I like it.
Data Binding is something to avoid in VB 6, but not in VB.NET !!
It takes me a lot of time to chose between using or not using bindings in VB.NET.
I didn't use binding in VB6 because I wanted to separate the business objects level against data access level. But one of the remarkable new features of VB.NET is the implicit separation between using the data (by DataSet) and accessing the data (by DataAdaptor). They bring the relational model at a high level and now you can use it directly in the business object tier. So you can directly use tables (and the data access will be defined by DataAdaptors, by SELECT statements or stored procedures).

About the original question I would use a datatable object for each table in the database and a data view for each data table. When you select an item in the first combo you will filter the data in the second combo by the corresponding dataview.

LVL 27

Expert Comment

ID: 10917047

I do agree with you concerning DataSets and DataAdpators and I use them too.
But it is the automatic binding to controls, specially to DataGrids that I find is problematic.
Just look at the miriads of questions here on EE that are related to bound DataGrids and you will know what I mean!

In the case in question, there are two possibilities:
Either we are talking about gigantic tables that fill the two combos, in which case I question if it is wise to present the data in a combo in the first place. (Do you want to scroll 1000 records down a combo until you find what you want?)
I assume we are talking about restricting data so that only a limited amount of it is shown in the combos, mainly the second one that depends on what is chosen in the first.
It can be done in several ways. I do not really think that it matters memory or timewise either way.
For somebody that is new to VB.NET that has tried to do it using temporary tables and it works - why complicate matters?
The fact that the SQL grows to 100mb in 20 mnts does not necessarily mean anything neither here nor there.
I doubt it happens because of the temporary tables used to fill two comboboxes.
If it did happen because of it, then probably most of the processing has been done on the server side, which probably is faster and less data goes down the network line.
Using DataViews and DataAdaptors, where would the processing be done? If on the server, then probably the server is still creating its own temporary tables and we would have a similar result. If on the client... will it be more effective???


Expert Comment

ID: 10925492
Using or not using a combo is a matter of number of items in the list. My number is one hundred. When the number of items in the list is less than 100 I use a combobox. When the number of items if greater than 100 I use a dialog form with a datagrid or a listview to select the desired line; the data in datagrid or listview can be sorted by clicking on the column header that help you to find quickly the record.
Since using comboboxes means few data you can load all the data in the memory in datatables.

About using DataBinding I said only a half of true. I use DataBinding to show the data but I dont use it to update the data. I use an edit form to add a new record or to modify the current record in the list, and then I add or modify the record in the datatable and in the list. The are some reasons for this approach:
-Using object oriented programming you need to have an intermediate level to validate the data, by the objects property functions, so the data have to pass through object before reach the datatable.
- A form is more appropriate to see a record than a datagrid line.
In a real database application there are a lot of foreign keys, that is you have columns with codes in the database table but you want to see names instead of codes, and these names are from a related table. It is easier to show these names in a form than in a list.
This is my approach to build my first VB.NET database application. I would like to hear another one!


LVL 27

Expert Comment

ID: 10925562
I agree with most of your approach.
With the exception that I do not DataBind.
I fill in the data into the control myself. It gives me more control of exactly what and where it gets displayed.
My experience with DataBinding (also in VB.NET) is that it is a great timesaver if all you want to do is show the data. But once you go into more complicated features, it turns to be a timewaster.

LVL 37

Expert Comment

ID: 10925585
based on your comment of "needing to watch memory size" read through my post again. The lazy reading pattern meets this concern in an attempt to push the decision of mempry footprint vs speed off to a configuration point (In other words it makes it so you can run small footprint now and later on when you have a bigger system change the configuration so that you can run faster with more memory utilization)

On your SQLServer benchmark 100 mb in 20 minutes is this memory usage or total database size gain ? If it is memory usage it is not a big deal ... worry more about your application memory usage unless SQL server starts pushing its thresholds and slowing down.

Author Comment

ID: 10925830
yea i agree with redundguy

i use these controls only to display the data. i don't like to update the backend db through these controls. some times it sucks.

comining to the memory size that is the size of the DB that grows to 100 mb in 20 mnts. (i should give an option in my application to take the back up of the DB automatically by checking the size of the DB or manually forcing the user to take, for each and every 20 mnts)
after going through all these replys, i have decided to create views for each combo control to display the data and to refresh when ever it is required.
thank you gregoryyoung once again hope your suggestions will help me in the long run ...

Mohan G

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question