Using hashTable to Insert records into Database

Last post 05-09-2008 5:35 PM by moises.dl. 1 replies.

Sort Posts:

  • Using hashTable to Insert records into Database

    05-09-2008, 12:01 PM

    I am using asp.net 2.0 with c#. I have two HashTable with values to be added inside my query. How do I add each value witth the correspoding key inside my query string.

    Here is my two HashTable
    Hash1.Add("1", "Bill");
    Hash1.Add("2", "Micheal");

    Hash2.Add("1", "Gates");
    Hash2.Add("2", "Jackson");

    Now here is what i have so far for the first HashTable

    IDictionaryEnumerator enumerator1 = Hash1.GetEnumerator();
    IDictionaryEnumerator enumerator2 = Hash2.GetEnumerator();

    while (enumerator1.MoveNext())
    {
       string Value1 = enumerator1.Value.ToString();

       cmd = new OracleCommand("Insert INTO MyTable FName, LName Values(Value1, Value2)", MyConn);
      
       cmd.ExecuteNonQuery();
    }


    Base on what i have provided, am I doing the right thing? Basically when this query is run it should have two rows in my database. "Bill Gates" and "Micheal Jackson". How do i accomplish this task?

    Don't forget to click "Mark as Answer" on the post that helped you.
  • Re: Using hashTable to Insert records into Database

    05-09-2008, 5:35 PM
    • Loading...
    • moises.dl
    • Joined on 09-12-2006, 11:17 AM
    • SLC
    • Posts 425

    first you completely forgot value2, so you will need to iterate them both and do a matching so you will need two loops or one loop but deal with two hashtables

    foreach (DictionaryEntry de in myHashtable)
    {
    string key = (string)de.Key;
    string val = (string)de.Value;
    since youre using the same key you can get the key from the first table then do somethin glike

    if(hash2.containskey(key)

    value2=hash2[key].value

    THEN do you sproc here
    }

    +
    I just want to let her know that im money and im here to party...
    +
    Entry Mid Lvl DRAGON MASTER SOFTWARE ENGINEER
Page 1 of 1 (2 items)