我对C#很陌生,现在我完全陷入了这个功能。 任何帮助将不胜感激。
我在mess.Add(firstname);
上收到OutOfMemoryException
我很确定这是因为阵列故障,但我似乎无法使其正常工作。
谁能以正确的方式指导我?
到目前为止,这是我的代码:
public List<string> SelectEmployee(string pkrelation)
{
SDKRecordset inboundSet = IQSDK.CreateRecordset("R_CONTACT", "", "FK_RELATION = " + pkrelation, "");
inboundSet.MoveFirst();
string person = inboundSet.Fields["FK_PERSON"].Value.ToString();
messages.Add(person);
inboundSet.MoveNext();
SDKRecordset inboundSet2 = IQSDK.CreateRecordset("R_PERSON", "", "PK_R_PERSON = " + person, "");
if (inboundSet2 != null && inboundSet2.RecordCount > 0)
{
inboundSet2.MoveFirst();
do
{
string firstname = inboundSet2.Fields["FIRSTNAME"].Value.ToString();
mess.Add(firstname);
inboundSet.MoveNext();
}
while (!inboundSet2.EOF);
return mess;
}
messages.Add("Error, didn't work.");
return messages;// null;
答案 0 :(得分:8)
你有一个错字。您不小心拥有inboundSet.MoveNext()
,因此您的inboundSet2.EOF
自然不会设置为false
,因为您从未实际迭代过它。这导致无限循环最终击中OutOfMemoryException
。
do
{
string firstname = inboundSet2.Fields["FIRSTNAME"].Value.ToString();
mess.Add(firstname);
inboundSet.MoveNext(); // This needs to be inboundSet2!
}
while(!inboundSet2.EOF) //EOF never becomes true causing an infinite loop