Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

Hashtables

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Softwaremaker - 03 Sep 2003 00:55 GMT
Hi all,

I am using a hashtable to store some values. However, I am not able to sort
the values in the hashtable based on an ascending order.

Seems to me that the hashtable can only sort the hash index of the values.
Is that true ?

Thank you.

Signature

William T
Software Architect / Chief Software Developer
Softwaremaker.Net Pte Ltd
http://www.Softwaremaker.Net

Chris Taylor - 03 Sep 2003 01:25 GMT
Hi,

That is correct the Hashtable can't sort the values. However you can use the
Values property of the Hashtable to get a collection of the values and then
create a ArrayList on the collection and sort it.

ArrayList a = new ArrayList( hash.Values ); // Create an ArrayList based on
the Hashtable values
a.Sort(); // Sort the ArrayList
...

Hope this helps

Chris Taylor
> Hi all,
>
[quoted text clipped - 5 lines]
>
> Thank you.
Yan-Hong Huang[MSFT] - 03 Sep 2003 03:58 GMT
Hello William,

Thanks for posting in the group.

Chris and You are right. HashTable can't sort the values by itself. For
this issue, I suggest you use SortedList. A SortedList is a hybrid between
a Hashtable and an Array. When an element is accessed by its key using the
Item indexer property, it behaves like a Hashtable. When an element is
accessed by its index using GetByIndex or SetByIndex, it behaves like an
Array.

In SortedList, the index sequence is based on the sort sequence. When an
element is added, it is inserted into SortedList in the correct sort order,
and the indexing adjusts accordingly. When an element removed, the indexing
also adjusts accordingly. Therefore, the index of a specific key-and-value
pair might change as elements are added or removed from the SortedList.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
!From: "Softwaremaker" <msdn@removethis.softwaremaker.net>
!Subject: Hashtables
!Date: Wed, 3 Sep 2003 07:55:47 +0800
!Lines: 17
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <OlL172acDHA.2904@TK2MSFTNGP11.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework
!NNTP-Posting-Host: bb220-255-10-104.singnet.com.sg 220.255.10.104
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework:52817
!X-Tomcat-NG: microsoft.public.dotnet.framework
!
!Hi all,
!
!I am using a hashtable to store some values. However, I am not able to sort
!the values in the hashtable based on an ascending order.
!
!Seems to me that the hashtable can only sort the hash index of the values.
!Is that true ?
!
!Thank you.
!
!--
!William T
!Software Architect / Chief Software Developer
!Softwaremaker.Net Pte Ltd
!http://www.Softwaremaker.Net
!
!
!
Softwaremaker - 03 Sep 2003 08:03 GMT
Thanks guys, I appreciate the response. Will make the necessary changes.

Thank you.

> Hello William,
>
[quoted text clipped - 56 lines]
> !
> !
param@community.nospam - 25 Oct 2007 16:25 GMT
Hey Guys,

I have been struggling with this for few days. when i use

SqlCacheDependency sqlDependency=new
SqlCacheDependency("test","dbo.USStates");

where test is the name of connectionstring and dbo.USStates is the table
name everything works fine.

but when i use

using (SqlConnection conn=new SqlConnection(connectionString))

{

SqlCommand command = new SqlCommand("[dbo].[USStatesGet]", conn);

command.CommandType = CommandType.StoredProcedure;

SqlCacheDependency sqlDependency = new SqlCacheDependency(command);

}

HttpRuntime.Cache.Insert(cacheName, ds, sqlDependency,
Cache.NoAbsoluteExpiration,Cache.NoSlidingExpiration);

then the cache is not being invalidated when the values are changed in the
table

the following is the stored procedure i am using

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[USStatesGet]

-- Add the parameters for the stored procedure here

AS

BEGIN

--SET NOCOUNT OFF;

SELECT [stateid]

,[statename]

FROM [dbo].[USStates]

END

Thanks in Advance

Param

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.