Hashtable对象以异常方式添加元素 [英] Hashtable object adding elements in an abnormal manner
本文介绍了Hashtable对象以异常方式添加元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我按照与我的数据库表格相同的顺序添加以下元素。
objHT.Add(< span class =code-string> P_NAME,sName);
objHT.Add( P_EMAIL,sEmail);
objHT.Add( P_CONTACTNO,sContact);
objHT.Add( P_COMPANY,sCompany);
objHT.Add( P_ADDRESS,sAddress);
objHT.Add( P_TIMELINE,sTimeline);
objHT.Add( P_BUDGET,sBudget);
objHT.Add( P_DETAILS,sPrjDtls);
objHT.Add( FILEPATH,sFilePath);
但是一旦代码执行,我发现它们按以下顺序添加:
email ,地址,详细信息,名称,联系方式,时间轴,filelpath,预算,公司
这会导致数据类型冲突的字段出现问题。
请建议我一个解决方案,或者我遗失了什么。
谢谢
IB
解决方案
添加到Hashtable时无法保证订单。
这就是hastables的工作方式。我想你必须使用OrderedDictionary Class [ ^ ]而不是。
感谢您的努力!但由于我不能使用不可靠的数据结构,我回到程序执行并自己解决它。实际上我正在尝试创建一个通用的库方法,可以简化任何插入操作的任务。 :)
I am adding the following elements in a proper sequence at par with my table in database.
objHT.Add("P_NAME", sName);
objHT.Add("P_EMAIL", sEmail);
objHT.Add("P_CONTACTNO", sContact);
objHT.Add("P_COMPANY", sCompany);
objHT.Add("P_ADDRESS", sAddress);
objHT.Add("P_TIMELINE", sTimeline);
objHT.Add("P_BUDGET", sBudget);
objHT.Add("P_DETAILS", sPrjDtls);
objHT.Add("FILEPATH", sFilePath);
but once the code is executed I find that they are added in the following order:
email, address, detail, name, contact, timeline, filelpath, budget, company
This is causing a problem as for fields there data type clash.
Please suggest me a solution or if 'am missing something.
Thanks
IB
解决方案
You are not guaranteed order when adding to a Hashtable.
That's how hastables work. I suppose you have to use a "OrderedDictionary Class"[^] instead.
Thanks for your efforts guys! but since i cannot use an unreliable data structure i fell back to procedure execution and solved it myself. Actually i was trying to create a generalized library method which could have eased the task for any insert operation. :)
这篇关于Hashtable对象以异常方式添加元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文