Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HashTable elements not found in the same order as they are added

HashTable elements not found in the same order as they are added

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mmdullah
    wrote on last edited by
    #1

    Hi all, I can not retrive the elements from a hashtable in the same order as they are added. please help......

    Hashtable htParameters = new Hashtable();
    htParameters.Add("fromDate", string.Format("'{0}'",fromDate.ToString("dd-MMM-yyyy")));
    htParameters.Add("ToDate", string.Format("'{0}'",toDate.ToString("dd-MMM-yyyy")));
    htParameters.Add("dtOvdDate", string.Format("'{0}'",dtOvdDate.ToString("dd-MMM-yyyy")));
    htParameters.Add("dtOvdDatePrev", string.Format("'{0}'",dtOvdDatePrev.ToString("dd-MMM-yyyy")));
    htParameters.Add("strAndPaid", string.Format("'{0}'",strAndPaid));
    htParameters.Add("rdoFileInfoSpecific", string.Format("{0}",rdoFileInfoSpecific.Checked?"1":"0"));
    htParameters.Add("SpecificFileNo", string.Format("'{0}'",txtFileInfoSpecific.Text.Trim()));
    htParameters.Add("strAndFOfficer", string.Format("'{0}'",strAndFOfficer));
    htParameters.Add("strAndZone", string.Format("'{0}'",strAndZone));
    htParameters.Add("strCollType", string.Format("'{0}'",strCollType));
    htParameters.Add("rdoStatusNID", string.Format("{0}",rdoStatusNID.Checked?"1":"0"));
    htParameters.Add("rdoStatusBankOpen", string.Format("{0}",rdoStatusBankOpen.Checked?"1":"0"));
    htParameters.Add("chkOvdVal", string.Format("{0}","0"));
    htParameters.Add("rdoRepTypeAllDet", string.Format("{0}",rdoRepTypeAllDet.Checked?"1":"0"));

    when retrieving..... they comes in different order

    if (parameters != null && parameters.Count > 0)
    {
    foreach (string parametername in parameters.Keys)
    {
    SqlParameter param = new SqlParameter("@" + parametername, parameters[parametername]);
    Cmnd.Parameters.Add(param);

                    }
                }
    

    plz reply asap mir

    S 1 Reply Last reply
    0
    • M mmdullah

      Hi all, I can not retrive the elements from a hashtable in the same order as they are added. please help......

      Hashtable htParameters = new Hashtable();
      htParameters.Add("fromDate", string.Format("'{0}'",fromDate.ToString("dd-MMM-yyyy")));
      htParameters.Add("ToDate", string.Format("'{0}'",toDate.ToString("dd-MMM-yyyy")));
      htParameters.Add("dtOvdDate", string.Format("'{0}'",dtOvdDate.ToString("dd-MMM-yyyy")));
      htParameters.Add("dtOvdDatePrev", string.Format("'{0}'",dtOvdDatePrev.ToString("dd-MMM-yyyy")));
      htParameters.Add("strAndPaid", string.Format("'{0}'",strAndPaid));
      htParameters.Add("rdoFileInfoSpecific", string.Format("{0}",rdoFileInfoSpecific.Checked?"1":"0"));
      htParameters.Add("SpecificFileNo", string.Format("'{0}'",txtFileInfoSpecific.Text.Trim()));
      htParameters.Add("strAndFOfficer", string.Format("'{0}'",strAndFOfficer));
      htParameters.Add("strAndZone", string.Format("'{0}'",strAndZone));
      htParameters.Add("strCollType", string.Format("'{0}'",strCollType));
      htParameters.Add("rdoStatusNID", string.Format("{0}",rdoStatusNID.Checked?"1":"0"));
      htParameters.Add("rdoStatusBankOpen", string.Format("{0}",rdoStatusBankOpen.Checked?"1":"0"));
      htParameters.Add("chkOvdVal", string.Format("{0}","0"));
      htParameters.Add("rdoRepTypeAllDet", string.Format("{0}",rdoRepTypeAllDet.Checked?"1":"0"));

      when retrieving..... they comes in different order

      if (parameters != null && parameters.Count > 0)
      {
      foreach (string parametername in parameters.Keys)
      {
      SqlParameter param = new SqlParameter("@" + parametername, parameters[parametername]);
      Cmnd.Parameters.Add(param);

                      }
                  }
      

      plz reply asap mir

      S Offline
      S Offline
      Seikilos
      wrote on last edited by
      #2

      This is in the nature of the hashtable. all elements are sorted by the hash of the key as mention here: http://msdn.microsoft.com/en-us/library/system.collections.hashtable.aspx[^] "Represents a collection of key/value pairs that are organized based on the hash code of the key." Use List< KeyValuePair< T,T > > for that unless you need an efficient by-key retrieval And please post code that compiles for others, like keep consistent field names (what is parameters?) and post code that works without rewriting all of your format variables.

      modified on Thursday, June 11, 2009 1:58 AM

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups