LLBLGen 2.6
VS2008
MSSql2005
I want to allow the user to pick a field to update and then send me a comma separated key/value pair file to update just the records in that file. So, I've got a table called "person" that has various fields like birthdate or gender or lastname. If they wanted to update the birthdate field, they'd send a comma separated list with person_id, birthdate. How can I make this work without a bunch of switch statements? Here's my attempt which I knew was doomed because of the casting error you'll see at the line that says:
person.Fields[fieldIndex].CurrentValue = personKeyPair[1];
...full method...
public static int ImportSingleField(string fileToOpen, int fieldIndex, short cbedsYear)
{
int recordsImported = 0; //Keep track of how many records are imported
using (StreamReader sr = new StreamReader(fileToOpen))
{
string line;
CbedsYearEntity cbedsYr = new CbedsYearEntity();
cbedsYr.FetchUsingPK(cbedsYear); //Get the year we're dealing with;
while ((line = sr.ReadLine()) != null)
{
PersonEntity person = new PersonEntity(); //Create a new PersonEntity instance
string[] personKeyPair = line.Split(',');
int localPersonID = Convert.ToInt32(personKeyPair[0].Trim('"'));
bool isFetched = person.FetchUsingUCLocalPersonIdCbedsYr(localPersonID.ToString().PadLeft(10, '0'), cbedsYear);
person.Fields[fieldIndex].CurrentValue = personKeyPair[1];
person.Save();
recordsImported++;
}
}
return recordsImported;
}
...what am I missing?