I'm allowing a user to attach a piece of information to a table. Before the INSERT statement, I put a check in to see if the table already contains that piece of information, and if so, give an alert dialog box to say, "oops, this is already in the table, no action taken."
To do this check, I'm simply using COUNT with the WHERE clause on the table to see if the data attempting to be entered is already there. I then set a boolean flag to true or false. True if the data is already there, and false if it is not.
This is the general idea of the code, with the SQL statements/parameters/etc. abbreviated:
protected void InsertPCButton_Click(object sender, EventArgs e)
Boolean alreadyattached = false;
using (SqlConnection myconn = new SqlConnection(sqlconnstring))
//SQL command/statements to get the count on the table
if (count != 0)
alreadyattached = true;
if (alreadyattached == true)
Response.Write("<script>alert('This PC is already attached to this case. No action taken.')</scrip
View Complete Post