string query = string.Format("INSERT INTO UserFavourite (UserID, FootballerID) VALUES('{0}',{1})", userid, fid);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
try{
cmd.ExecuteNonQuery();
}
catch(SqlException ex){
// Promt user
}
con.Close();
amereto2k:Could you brief me on what the stringbuilder part is it and how would you promt the user?
Sorry the StringBuilder part is left over, from a copy/paste. Don't mind that, you don't need it, it was in the sample i copied from used to display the error messages from the SqlException.
string query = string.Format("INSERT INTO UserFavourite (UserID, FootballerID) VALUES('{0}',{1})", userid, fid);
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
try{
cmd.ExecuteNonQuery();
}
catch(SqlException ex){
//Promt user
}
con.Close();
On pages where i need dynamically to promt user, i place a Label control on the page called lblError, with red bold font. And then when i need to promt the user i simply add some text to the label by lblError.Text = "You have already added the player to your favorites";
Otherwise you will have to redirect to a other page, but in your case that doesn't make sense in my oppionion.
/Regards Anders