Field References

6 views
Skip to first unread message

garyp

unread,
Jul 30, 2009, 7:34:56 PM7/30/09
to CSVChat
Hi

Could it be possible for a future release to throw an error when we
try to reference a field that doesnt exist e.g.

ir.BSB_No = csvData["BDB No"];

"BDB No" should be "BSB No" but there is no indication that we have
misstyped the fieldname

Cheers

gary

shriop

unread,
Jul 30, 2009, 10:52:23 PM7/30/09
to CSVChat
It was an intentional feature so probably not unless it no longer
makes sense to me. It made sense to me at the time anyways. There is a
way to tell whether the column actually exists however if you just
slightly change your syntax and use this example method.

ir.BSB_No = GetValue(csvData, "BDB No");

...

private static string GetValue(CsvReader reader, string field)
{
int index = reader.GetIndex(field);

if (index == -1)
{
throw new Exception("Field named " + field + " does not exist in
reader.");
}
else
{
return reader[field];
}
}

Bruce Dunwiddie

garyp

unread,
Jul 31, 2009, 12:31:37 AM7/31/09
to CSVChat
Thanks for the reply

I knew about GetIndex just didnt think of using it that way!!

Cant see the wood for the trees today

Cheers

Gary
> > gary- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages