Solved

Add HashTable as Value inside another Hashtable

Posted on 2006-11-21
2
190 Views
Last Modified: 2010-04-23
How can I reuse htFields inside the For Each loop?

I want to add htFields as the value for the matching key inside htTables




    dim htTables as New Hashtable()

    for each str as String in GetTableNames(conn)
      debug.WriteLine(str)
      htTables.Add(str,Nothing)
      conn.Open
      Dim cmd1 As OleDb.OleDbCommand = New OleDb.OleDbCommand("select * from " & str, conn)
      Dim dra As IDataReader = cmd1.ExecuteReader(CommandBehavior.SchemaOnly Or CommandBehavior.KeyInfo)
      Dim dta As DataTable = dra.GetSchemaTable()
      Dim myrow As DataRow
      For Each myrow In dta.Rows
        Debug.WriteLine("Column Name:  " + myrow(0).ToString)
        dim htFields As New Hashtable()
        htFields.Add(myrow(0).ToString(),false)
      Next
      htTables(str) = htFields

      htFields = Nothing
      dra.Close
      conn.Close
    Next
0
Comment
Question by:knowlton
2 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 500 total points
ID: 17991978
because you declare htFields inside the inner loop, it will only be accessible during that iteration, ie once out of the for each myrow loop the object htFields is not accessible

if you declare the htfields object outside the loop, you can use it inside the for each myrow loop and it will still exist outside that loop as well.

eg
dim htFields As New Hashtable()
 For Each myrow In dta.Rows
        Debug.WriteLine("Column Name:  " + myrow(0).ToString)
                htFields.Add(myrow(0).ToString(),false)
      Next
 htTables(str) = htFields

0
 
LVL 5

Author Comment

by:knowlton
ID: 17992107
That was it, thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

22 Experts available now in Live!

Get 1:1 Help Now