[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Add HashTable as Value inside another Hashtable

Posted on 2006-11-21
2
Medium Priority
?
197 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 2000 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:Tom Knowlton
ID: 17992107
That was it, thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 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