Well, you can change/fix the store procedure to check for this, and not allow the update.
Or maybe you create a trigger that when you set one to true, it sets all others = false.
but, if you want to check this at the UI level BEFORE all that behind stuff occurs?
I would consider just coding out the condition, and checking - that way you can give the user some nice friendly feedback.
so, code in that update could do say this (air code)
string strSQL = "SELECT MachineID FROM tblMachines where MachineID <> @ID" +
"AND PersonID = @PersonID AND IsPrimary = 1";
using (SqlCommand cmdSQL = new SqlCommand(strSQL,
new SqlConnection(Properties.Settings.Default.TEST4)))
{
cmdSQL.Parameters.Add("@MachineID", SqlDbType.Int).Value = "the machine ID";
cmdSQL.Parameters.Add("@PersonID", SqlDbType.Int).Value = "the person id";
cmdSQL.Connection.Open();
string PK = Convert.ToString(cmdSQL.ExecuteScalar());
if (PK == "")
{
Response.Write("<h2>ok, we can do this - no rows returned</h2>");
}
else
{
Response.Write("<h2>Already a machine set as primary for this user-</h2>");
}
}
So even if you setup a stored procedure to not allow this, you near in all cases will want to check/test/inform the user in actual use of such rules. So you can setup the rule to not allow this, but my bets suggest that you still need to test/check/try and take actions - actions that will give some type of feedback on this not being allowed. (like say maybe a way cool looking jQuery.UI dialog box).
Regards,
Albert D. Kallal (Access MVP 2003-2017)
Edmonton, Alberta Canada