Solved

Use a hash table to hold URLs then display to GridView

Posted on 2006-07-13
12
867 Views
Last Modified: 2007-12-19
I have not used Hash tables.  My understanding is that people use these to hold IDs from a DB (after referencing a stored proc) then spit out the data in the hash table such as ID, Name, and other fields from the stored proc into a DataGrid....better yet, in my case, I want to spit it out into a GridView.

Tell me, am I correc, this is a technique that is used?  If so, why no datasets?

Anyway, I need help in how to create a class that I could use in C# and a hash table somewhere to do just that.  Populate my GridView in my aspx page.

I'm not sure where to start...I guess create my .cs page or linked library?  Not sure what to do here.  I am new at C#...very novice so please don't assume the simplest is known.  I know how to in the past  populate a  GridView using a Dataset in code-behind but now I'm working in a real OOP environment at a new company trying to figure this out on my own time.
0
Comment
Question by:dba123
  • 6
  • 5
12 Comments
 
LVL 3

Expert Comment

by:BBK_
ID: 17105702
HashTable is a data structure to store values with a Key.
The real advantage of it is the Value can be identified using the Key.

EG; You have an employee class, which has many data regarding a particular employee.
       So you are adding the employees into hash table with EmployeeID as Key
EG:
            
      HashTable H = new Hashtable();
      H[“EMP01”] =       <Employee instance>

      By doing so, when you get an employee ID corresponding Employee details can be fetched from hash table with out any looping

EG         <Employee Instance> = H[“EMP01”];

The advantage of Hash table is, it is fast in accessing the Value, If you know a key.

Key and Value of hash table can have of any type
0
 
LVL 1

Author Comment

by:dba123
ID: 17105721
Yea, so a Hash table is just another way to store data, just like a dataset does right?
0
 
LVL 3

Expert Comment

by:BBK_
ID: 17105739
Answer to the second part

Technically the data access and business part has to be on another assemble ( The Ideal OOPS approach)
B’ce the presentation layer (aspx) should be always separated from Business layer. And Presentation layer should only know the business layer, means Business layer should not Know Presentation layer

So in code behind of aspx file should have only the code which link the aspx controls and Business layer and the code to manipulate the presentation.

You can keep the business layer as a separate project in a separate namespace
0
 
LVL 1

Author Comment

by:dba123
ID: 17105740
so let's say I have a  stored proc:

select EmployeeID, EmployeeName FROM tablename

Then the hash table  will load in the data from the stored proc

Then I can use the hash table as a data source for my GridView and the advantage here is not having to loop?  But you don't loop if you load a data with a dataset either.  I assume a  hash table is more efficient and less resource intensive then?  I just came to a new job for a .com and just have never seen anyone use a hash table for loading DataGrids, etc.  I'm s ure this is a great way to do it, just trying to understand if this is why.  I have read so much about datasets and used datasets that I"m not yet familiar with this approach and why.
0
 
LVL 1

Author Comment

by:dba123
ID: 17105748
>> Technically the data access and business part has to be on another assemble ( The Ideal OOPS approach)

you are correct, that's how the architecture is setup, also which is sort of new to me...
0
 
LVL 1

Author Comment

by:dba123
ID: 17105754
so you're saying this (please clarify, I'm new to this complete separation in C# environment):

aspx contains the GridView control obviously
A class contained in a .cs file in the business  layer contains the hash table
The hash table calls the stored proc which brings back the key/value pairs and holds it somehow, I assume in memory?
When the aspx page is loaded, it calls the class, which binds the data in the hash table to the GridView control

??
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Expert Comment

by:BBK_
ID: 17105760
In one way you are right, both hashtable and Dataset can store data. But its application /Usage are different.
If I put it another way dattype Integer and string, both can store data, but it’s usage are different

0
 
LVL 3

Expert Comment

by:BBK_
ID: 17105787
No, You cannot use HashTable as a datasource of any control
Datasource will not allow list like controls
In your scenario the better approach will be using a datareader or dataset/ datatable to bind the data to the control.
0
 
LVL 1

Author Comment

by:dba123
ID: 17105821
ahh, nevermind, I looked back at a question I had in the interview.  Yes, I'm still using a dataset to bind to the GridView.  I guess they were using a hash table to hold the items the user added to their shopping cart in the example I had to try to code.
0
 
LVL 3

Expert Comment

by:BBK_
ID: 17105907
Any more clarification required ?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17108278
Remember that hash tables are meant to provide fast look-up, on the order O(1).  This means that no matter how many items you have in the table, it stays constant on speed of lookup.  It cannot, though, become a data storage structure, since it doesn't respect the order of things.  The hash table stores element in a slot, and uses a repeatable algorithm to calculate where that spot is, and retrieve it very quickly.  So, the key must be unique so that you can lookup a single object.

Using the right tool for the job is very much a part of software development, so it helps to get inside each class structure and get a detailed understanding of the underlying concepts.

Bob
0
 
LVL 1

Author Comment

by:dba123
ID: 17108308
thanks, yea, I haven't been able to see the code here yet at my new job, just started and don't have VSS installed yet.  I'll have to see how they used hash tables so far and in what situations.

Thanks for the last explanation.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

20 Experts available now in Live!

Get 1:1 Help Now