why don't you use a Stored Proc to execute the same. In that proc you can use Return statements and fetch those in your program to set the values and it is safer and easy as well.
The program would be :-
If exists( select the criteria)
BEGIN
(write the program logic here and then return a suitable return code)
RETURN 1;
END
ELSE
return 0;
In your code, you can use
SqlCommand command= new SqlCommand("procname",Connection);
Sqlparameter parret=new sqlparameter();
parret.Direction= parameterDirection.ReturnVal;
Command.CommandType=CommandType.StoredProcedure();
.
.
.
cmd.ExecuteNonQuery();
fetch the return value and then proceed.
.
.
.
I have not used any tool to type the code, so the codes might vary, but the logic remains the same.
Hope this helps. Or else, the other options would work good but are not safe if proper validations are not made on front end.