I have an upload button that can upload excel file and save it to my database. What I want to happen is that if there's one or more data in that excel file that already existing the other data will also not be uploaded though it's not yet existing. My code for adding it to the database and upload button are below.

Add to database

```
 private void AddNewTrainee(string strdelname, string strrank, string strcomp, string strcourse, string strcenter, string strinst,
                            string strsdate, string stredate, string strcissued, string strcnumber, string strremark, int recdeleted, string credate, string update, int fromupload)
{
    connection.Open();
    String checkDateAndName = "Select count(*) from Trainees where StartDate= '" + strsdate + "' and Delegate='" + strdelname + "' and REC_DELETED = 0  ";
    SqlCommand cmd = new SqlCommand(checkDateAndName, connection);
    int dataRepeated = Convert.ToInt32(cmd.ExecuteScalar().ToString());
    bool boolDataRepated;
    connection.Close();

    if (!(dataRepeated >= 1))
    {
        boolDataRepated = false;
    }
    else
        boolDataRepated = true;

    connection.Open();
    string certNumber = "Select * from CertID_Table update CertID_Table set CertificateID = CertificateID + 1 from CertID_Table ";
    SqlCommand cmdCert = new SqlCommand(certNumber, connection);

    using (SqlDataReader oReader = cmdCert.ExecuteReader())
    {
        while (oReader.Read())
        {
            string test1 = oReader["CertificateID"].ToString();
            ViewState["certnumber"] = test1;
        }
    }
    connection.Close();
    strcnumber = (string)ViewState["certnumber"];

        if (boolDataRepated == false)
        {
            string path = "D:\\Intern\\BASSWeb\\SQLCommands\\AddSQL.txt";
            StringBuilder sb = new StringBuilder();
            using (StreamReader sr = new StreamReader(path))
            {
                while (sr.Peek() >= 0)
                {
                    sb.Append(sr.ReadLine());
                }
                string sql = sb.ToString();
                try
                {
                    connection.Open();
                    SqlCommand cmd1 = new SqlCommand(sql, connection);
                    cmd1.Parameters.AddWithValue("@delName", strdelname);
                    cmd1.Parameters.AddWithValue("@rank", strrank);
                    cmd1.Parameters.AddWithValue("@comp", strcomp);
                    cmd1.Parameters.AddWithValue("@course", strcourse);
                    cmd1.Parameters.AddWithValue("@center", strcenter);
                    cmd1.Parameters.AddWithValue("@instructor", strinst);
                    cmd1.Parameters.AddWithValue("@sdate", strsdate);
                    cmd1.Parameters.AddWithValue("@edate", stredate);
                    cmd1.Parameters.AddWithValue("@cissued", strcissued);
                    cmd1.Parameters.AddWithValue("@cnumber", strcnumber);
                    cmd1.Parameters.AddWithValue("@remark", strremark);
                    cmd1.Parameters.AddWithValue("@rdeleted", recdeleted);
                    cmd1.Parameters.AddWithValue("@cdate", credate);
                    cmd1.Parameters.AddWithValue("@udate", update);
                    cmd1.Parameters.AddWithValue("@fupload", fromupload);
                    cmd1.CommandType = CommandType.Text;
                    cmd1.ExecuteNonQuery();
                }
                catch (System.Data.SqlClient.SqlException ex)
                {
                    string msg = "Insert/Update Error:";
                    msg += ex.Message;
                    throw new Exception(msg);
                }
                finally
                {
                    connection.Close();
                }
            }
        }
        else
        {
            string script = "alert(\"The data already exists\");";
            ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true);
        }
}

```

Upload Button 

```
 protected void btnUpload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile)
    {
        try
        {
            string path = Path.GetFileName(FileUpload1.FileName);
            path = path.Replace(" ", "");
            FileUpload1.SaveAs(Server.MapPath("~/Datas/") + path);
            String ExcelPath = Server.MapPath("~/Datas/") + path;
            OleDbConnection mycon = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + ExcelPath + "; Extended Properties=Excel 8.0; Persist Security Info = False");
            mycon.Open();
            OleDbCommand cmdX = new OleDbCommand("select * from [Sheet1$]", mycon);
            OleDbDataReader dr = cmdX.ExecuteReader();
            while (dr.Read())
            {
                delegateName = dr[0].ToString();
                rankPos = dr[1].ToString();
                company = dr[2].ToString();
                courseTitle = dr[3].ToString();
                trainingCenter = dr[4].ToString();
                instructor = dr[5].ToString();
                staDa = DateTime.Parse(dr[6].ToString());
                string startDate = staDa.ToString("MM/dd/yyyy");
                endDa = DateTime.Parse(dr[7].ToString());
                string endDate = endDa.ToString("MM/dd/yyyy");
                certIssued = dr[8].ToString();
                certNum = dr[9].ToString();
                remarks = dr[10].ToString();
                recDeleted = 0;
                dateCreated = DateTime.Now.ToString("MM/dd/yyyy HH:mm");
                dateUpdated = string.Empty;
                fromUpload = 1;
                AddNewTrainee(delegateName, rankPos, company, courseTitle, trainingCenter, instructor, 
                    startDate, endDate, certIssued, certNum, remarks, recDeleted, dateCreated, dateUpdated, fromUpload);
            }
        }
        catch (Exception ex)
        {
            string errorMessage = "alert(\"ERROR: " + ex.Message.ToString() + " \");";
            ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", errorMessage, true);
        }
    }
    else
    {
        string errorMessage = "alert(\"ERROR: You have not specified a file \");";
        ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", errorMessage, true);
    }
    PopulateData();
}

```