I once was an IBM 360 ALC programmer (obviously many years ago) and have learned C#, SQL and Webmatrix as a hobby in my golden years. I am using Webmatrix for storing scores and calculating results for a retired men's golf group. We play weekly and there are about 30+ players so the number of records is small. My program requires a couple of querys and many individual record updates. This seems the wrong way to do things and I am wondering how to bring the records into memory and do the sorting and calculating there followed by a batch update. I have poured through MSDN and many other sites looking for techniques to bring the records in as a multicolumn array to no avail. Here is what I am doing now. I'd like to learn from this audience a better way to accomplish the task.
vargetRoundResults="Select * FROM Scorecards WHERE SchedID=@0 ORDER BY IDX";varsortRoundResults="Select * FROM Scorecards WHERE SchedID=@0 ORDER BY Flight, Net,IDX DESC";varsetFlight="UPDATE Scorecards SET Flight=@0 WHERE PKey =@1 AND SchedID=@2";varsetPlace="UPDATE Scorecards SET Place=@0 WHERE PKey =@2 AND SchedID=@3";
nop=0;foreach(varrindb.Query(getRoundResults,schedid)){nop=nop+1;// count number of players}nf=nop/2;// cut in half for flightsnfr=nop%2;// handle odd numbers i=fn=1;foreach(varrowindb.Query(getRoundResults,schedid)){pkey=row.PKey;if(i<=nf){db.Execute(setFlight,1,pkey,schedid);// Assign Flight 1 to first halfi++;}else{db.Execute(setFlight,2,pkey,schedid);i++;}}i=fn=1;foreach(varrowindb.Query(sortRoundResults,schedid)){pkey=row.PKey;fn=row.Flight;if(i<4&&fn==1){db.Execute(setPlace,i,pkey,schedid);// asigns place 1 flight 1 and place for 2, 3 both flightsi++;}else{if(i>nf&&fn==2){pl=i-nf;if(pl<4){db.Execute(setPlace,pl,pkey,schedid);// assign place 1 and flight 2}i++;}else{i++;}}}