Solved

Add HashTable as Value inside another Hashtable

Posted on 2006-11-21
2
194 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 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:Tom Knowlton
ID: 17992107
That was it, thanks.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP/VB email question 4 62
VB.net and sql server 4 54
DataGridView / get bound table name? 8 36
DataMember property 'tablename' cannot be found on the DataSource. 4 52
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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