Reputation: 4142
I'm quite new into C# and right now I'm totally stuck into this function. Any help would be appreciated.
I'm getting an OutOfMemoryException on mess.Add(firstname);
I'm pretty sure it's because of an array fault but I can't seem to make it work.
Who can guide me in the right way?
This is my code so far:
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;
Upvotes: 1
Views: 183
Reputation: 23208
You have a typo. You accidentally have inboundSet.MoveNext()
so naturally your inboundSet2.EOF
is never set to false
because you never actually iterate through it. This causes an infinite loop eventually hitting the 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
Upvotes: 8