have a small code snippet in c# just accessing a varable that has been set the time before but cannot see the varable at block level and cannot seem to set it and hold it.
so the first time through it will return a value of the new record created,
int recVal; // this is the varable that needs to be held and used again
foreach (DataRow dr in dt.Rows)
{
// FROM HERE GO AND CYCLE THROUGH THE DOCUMENT AND LOOK FOR LIKE DATA
fndtest = findtext(sqlstringstart, sqlstringFinished, textBox1.Text, dr["Tabletosaveto"].ToString(), dr["fieldtosaveto"].ToString());
MessageBox.Show(dr["firstfield"].ToString());
if (dr["firstfield"].ToString() == "Y")
{
// FIRST TIME THROUGH THE SYSTEM FINDS THE NEW REC NUMBER
// AND WILL PLACE IT IN recVal after it has been cnverted to int this works but next time
// through the recVal is not defined as it moves from the block to function, have set the
// recVal out side the block any ideas on what i am doing wrong please
IDNumber = SaveField(sqlTabletosaveto, fieldtosaveto, fndtest,'Y',0);
recVal = Int32.Parse(IDNumber);
}
else{
// SECOND TIME THROUGH IT USES recVal TO FIND THE NEW RECORD AND UPDATE THE FIELD
IDNumber = SaveField(sqlTabletosaveto, fieldtosaveto, fndtest, 'N', recVal);
}
}
" Error 23 Use of unassigned local variable 'recVal' "
just throws up an error, before i do any thing