title: How to find duplicate values while importing excel and displays an error message on the same table where imported data displays?
body: <p>I am using MVC with C#, I am trying to import an excel sheet and validate those sheet and displays the excel data along with error message on one column in a table. If got any error my selection checkbox will not available, so the user cannot select and save the particular record. my page is actually working. What is my issue right now is, I wanna add Unique id validation. which means I have one Id column, where I don't want duplicate value. I added validation to check with my table and if found any same id, it returns an error message. but, <strong>if let say, user upload duplicate values on the excel sheet when they upload means, how to find out while uploading and how to prevent them from adding duplicate id records.</strong></p>
  
  <p>my sample coding below.</p>
  
  <pre><code>if (theFile != null &amp;&amp; theFile.ContentLength &gt; 0)
  {
      try
      {
          string[,] data = ExportUtil.GetData(theFile);
  
          int rowValue = data.GetLength(0);
          int colValue = data.GetLength(1);
  
          Info _I;
          ViewModel _VM;
  
  
          for (int i = 0; i &lt; rowValue; i++)
          {
  
              _VM= new ViewModel();
             // _VM.Id = i;
              _VM.Id = data[i, 0].ToString() != null ? data[i, 0].ToString() : "";
              _VM.Description = data[i, 1].ToString() != null ? data[i, 1].ToString() : "";
  
  
              if (string.IsNullOrWhiteSpace(_VM.Id))
              {
                  _VM.Message = "Id cannot be empty" + System.Environment.NewLine;
              }
              _ID = TagInfo.Where(a =&gt; !string.IsNullOrEmpty(_VM.Id) &amp;&amp; a.Id.ToUpper() == _VM.Id.ToUpper()).FirstOrDefault();
              if (_ID != null)
              {
                  _VM.Message += "Duplicate ID" + System.Environment.NewLine;
                  _ID =null;
              }
              if (string.IsNullOrEmpty(_VM.Description))
              {
                  _VM.Message += "Description cannot be empty" + System.Environment.NewLine;
              }
  
  
              if (!string.IsNullOrEmpty(_VM.Message))
              {
                  _VM.Message = string.Format("{0}{1}", "Row Number " + (i + 1) + " has " + Environment.NewLine, _VM.Message);
  
              }
  
              listvm.Add(_VM);
  
          }
  
          TempData["ID_DOWNLOAD"] = listvm;
  
  
      }
  }
  </code></pre>
  
  <p><code>_ID</code> I declared with table name <code>TableID _ID</code>; above the try block. kindly help.</p>