Solved

Use a hash table to hold URLs then display to GridView

Posted on 2006-07-13
12
876 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bulid json format 3 46
How to LOAD up a .NET Framework website with data? 2 40
C# HTTP GET method sample code 3 40
Error in script 11 45
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

15 Experts available now in Live!

Get 1:1 Help Now