Capturing the UN-UPDATED records
-
for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....
-
for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....
Since this is not VB6 and you cannot Resume Next On Error, I guess you better validate what you're updating before trying to update it, and if it doesn't validate, not try to update. Simply. Thus, you get no exceptions and the for loops for as long as you want it to loop :)
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
-
for (i=1;i=5;i++) { int a=i; sqlinsert="update tbl_name set loop_no=a where rollnumber=a"; cmd = new SqlCommand(sqlinsert, conn); try { cmd.ExecuteNonQuery(); } catch(Exception ex) { FileStream fs; StreamWriter sw; fs=new Filestream("logfile.txt",FileMode.open); sw=new StreamWriter(fs); string newline="Roll No:"+a+"was not updated"; sw.close(); fs.close(); } } once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop???? i tried.. but getting error... how to achieve it? thanks in advance and understanding....
John Sundar wrote:
once if its go for "CATCH" block, how it can proceed others? i.e, if record 2 fails, will it proceed other records and complete the whole FOR loop????
The try/catch block is within the body of the loop. If an error occurs during one iteration of the loop, it will be caught and the code will proceed to subsequent iterations.
John Sundar wrote:
i tried.. but getting error...
You need to post details of the error if you want help. We're not mindreaders.
John Sundar wrote:
how to achieve it?
Post details of your error, and maybe you'll get some help.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush