title: Is there a way to check if data from a text file exist in the database?
body: <p>Using a stream reader to read a text-file (.txt) data, then save it to the database. Is there a way to check if the same data exist in the database while a user is trying to read/save same text-file??</p>
  
  <p>this is the  code to browse and open a text file:</p>
  
  <pre><code>OpenFileDialog openFileDialog1 = new OpenFileDialog
  {
      InitialDirectory = @"C:\",
      Title = "Browse Text Files",
  
      CheckFileExists = true,
      CheckPathExists = true,
  
      DefaultExt = "txt",
      Filter = "txt files (*.txt)|*.txt",
      FilterIndex = 2,
      RestoreDirectory = true,
  
      ReadOnlyChecked = true,
      ShowReadOnly = true
  };
  
  if (openFileDialog1.ShowDialog() == DialogResult.OK)
  {
      textBox1.Text = openFileDialog1.FileName;
  }
  </code></pre>
  
  <p>This is the code to READ AND SAVE DATA TO THE DATABASE:</p>
  
  <pre><code>if (textBox1.Text != "")
  {
      List&lt;string&gt; names = new List&lt;string&gt;();
      string message = "Data Submitted Successfully";
  
      string line;
      using (SqlConnection con = new SqlConnection("Data Source=THABO\\SQLEXPRESS;Initial Catalog=Airtime;Integrated Security=True"))
      {
          con.Open();
          using (StreamReader file = new StreamReader(@textBox1.Text))
          {
              while ((line = file.ReadLine()) != null)
              {
                  string[] fields = line.Split('|');
  
                  SqlCommand cmd = new SqlCommand("INSERT INTO Voucher(Currency,Nomination) VALUES (@Currency,@nomination,)", con);
                  cmd.Parameters.AddWithValue("@currency", fields[0].ToString());
                  cmd.Parameters.AddWithValue("@nomination", fields[1].ToString());
                  cmd.ExecuteNonQuery();
              }
          }
          con.Close();
  
      }
  }
  </code></pre>
  
  <p>The code works fine , i want to validate (so a user can't save/read same data from a textfile to the database)</p>