HashTable elements not found in the same order as they are added
-
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
-
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
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