Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL

Hi All,

I will return an output of the query
Select Key_Column,Value_column from MyTable
to C# code. This has to be directly stored into a HashTable. Is this possible ?

Please suggest...


Thanks & Regards,
Mathi.
Posted

try this after getting result in reader:-

C#
while (rs.next() == true)

                  {
                 key = rs.getString(1);

                 value = rs.getString(2);

                 hash.put(key,value);
                //Hashtable populated

             }
 
Share this answer
 
Comments
Mathi2code 22-Apr-13 1:45am    
What is 'rs' here can you tell me how to populate that rs too....
TrushnaK 22-Apr-13 6:43am    
Its a data reader. After getting data from database you use reader to read that afterwords take its first string as key and 2 for value as above mention.
Mathi2code 29-Apr-13 1:32am    
Hi TrushnaK
Thanks a lot this helped. Is there anyother way without looping we can directly load a dataTable to hashtable or the vice-versa stuff

Regards,
Mathi
You can save the datable returned from the DB into a hashtable ...
Refer this for more info...
http://forums.asp.net/t/1508834.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900