Solved

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

Posted on 2004-04-25
10
2,618 Views
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
0
Comment
Question by:gkmohan2003
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 27

Expert Comment

by:Dabas
ID: 10913663
Hi gkmohan2003:
> Is this approach is correct.
YES!
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.


Dabas
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 50 total points
ID: 10913919
>> Is this approach is correct.
>YES!


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 ...
0
 
LVL 37

Expert Comment

by:gregoryyoung
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.
0
 

Author Comment

by:gkmohan2003
ID: 10915687
hi
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...


0
 
LVL 1

Accepted Solution

by:
redundguy earned 75 total points
ID: 10916297
Dabas,
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.

George
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 27

Expert Comment

by:Dabas
ID: 10917047
George:

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???


Dabas
0
 
LVL 1

Expert Comment

by:redundguy
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!

George

0
 
LVL 27

Expert Comment

by:Dabas
ID: 10925562
George:
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.

Dabas
0
 
LVL 37

Expert Comment

by:gregoryyoung
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.
0
 

Author Comment

by:gkmohan2003
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 ...

bye
Mohan G
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now