1. If you are not familiar with C# and sql, then you should go through
Using Parameterized SQL[
^] first.
2. Once you have completed Point 1, adapt the following code snippet to check if certain record exists in the database.
string selectSQL = "select count(*) from tablename where somefieldname = @somevalue";
SqlCommand cmd = new SqlCommand(selectSQL);
cmd.Parameters.AddWithValue("@somevalue", TextBox1.Text.Trim());
Int32 rowCount = (Int32) cmd.ExecuteScalar();
3. After Point 3,
if (rowCount == 0){
// execute sql insert, adapt example in point 1
}
else
{
// execute sql update, adapt example in point 1
}
End of lesson.