//CHECK IF COMPLETE DUPLICATE
query = "SELECT * FROM TBL_FLAVORS WHERE flavor_name = @flavor_name AND flavor_supplierid = @supplier_id";
using (SqlConnection con = new SqlConnection(connstring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(query, con))
{
SqlDataReader read;
cmd.Parameters.AddWithValue("@flavor_name", txtFlavorName.Text.ToString());
cmd.Parameters.AddWithValue("@supplier_id", supplierid);
read = cmd.ExecuteReader();
if (read.Read())
{
MessageBox.Show("This flavor for this supplier already exists.");
return;
}
read.Close();
}
}
//CHECK IF ALMOST SIMILAR
//IF RECORD FOUND, RETURN
//OTHERWISE, PROCEED TO UPDATE/INSERT
query = "SELECT * FROM TBL_FLAVORS WHERE (flavor_name LIKE @flavor_name OR flavor_name LIKE @flavor_name2 OR FLAVOR_NAME LIKE @flavor_name3) AND flavor_supplierid = @supplier_id";
using (SqlConnection con = new SqlConnection(connstring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(query, con))
{
string flavorname = "%" + txtFlavorName.Text.ToString()+ "%";
string flavorname2 = "" + txtFlavorName.Text.ToString() + "%";
string flavorname3 = "%" + txtFlavorName.Text.ToString() + "";
SqlDataReader read;
cmd.Parameters.AddWithValue("@flavor_name", flavorname);
cmd.Parameters.AddWithValue("@flavor_name2", flavorname2);
cmd.Parameters.AddWithValue("@flavor_name3", flavorname3);
cmd.Parameters.AddWithValue("@supplier_id", supplierid);
read = cmd.ExecuteReader();
if (read.Read())
{
DialogResult dialog = MessageBox.Show("It is possible that this flavor for this supplier already exists. Do you want to continue?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialog == DialogResult.No)
{
return;
}
}
read.Close();
}
}
The panelist asked what if there was already an 'inch' and the user entered an 'innch.' It should be recognized as a duplicate. Or say there is a 'chocolate' in the database, it should ask for confirmation if the user enters 'chocolates'.