title: Import Excel to Database
body: <p>I'm trying to import an excel document into a database.</p>
  
  <p>I have successfully done this, however, the problem that occurs is that, the data I'm trying to insert, gets inserted four times instead of once. </p>
  
  <p>Here is my code: </p>
  
  <pre><code>private void upload_button_Click(object sender, EventArgs e)
  {
      if ((tick.Visible != true)|(string.IsNullOrWhiteSpace(cat_combobox.Text))|(string.IsNullOrWhiteSpace(subcat_combobox.Text)))
      {
          MessageBox.Show("Select an excel file.", "Error: Missing Excel Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      else
      {
          try
          {
              FileStream fs = File.Open(filepath, FileMode.Open, FileAccess.Read);
              IExcelDataReader excelreader = ExcelReaderFactory.CreateOpenXmlReader(fs); //'97-03 USE: CreateBinaryReader, 07+ USE: CreateOpenXmlReader
              //CREATE COLUMN NAMES FROM FIRST ROW
              excelreader.IsFirstRowAsColumnNames = true;
              DataSet ds = excelreader.AsDataSet();
              DataTable dt = new DataTable();
              dt = ds.Tables[0];
              while (excelreader.Read())
              {
                  foreach (DataRow row in dt.Rows)
                  {
                      if ((!(row["Item"].Equals(DBNull.Value))) | (!(row["Quantity"].Equals(DBNull.Value))) | (!(row["Date"].Equals(DBNull.Value))))
                          importtodb(Convert.ToInt32(this.cat_combobox.SelectedValue), this.subcat_combobox.Text.ToString(), row["Item"].ToString(), Convert.ToInt32(row["Quantity"]), row["Date"].ToString());
                  }
              }
              excelreader.Close();
              this.DialogResult = DialogResult.OK;
              this.Close();
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
  
  }
  
  private void importtodb(int catid, string subcat, string item, int quantity, string date)
  {
      using (var sqlcmd = new SqlCommand("INSERT INTO inventory_table (categoryid, Subcategory, Item, Quantity, Date) VALUES(@catid, @subcat, @item, @quantity, @date)", sqlconnection))
      {
          sqlcmd.Parameters.AddWithValue("@catid", catid);
          sqlcmd.Parameters.AddWithValue("@subcat", subcat);
          sqlcmd.Parameters.AddWithValue("@item", item);
          sqlcmd.Parameters.AddWithValue("@quantity", quantity );
          sqlcmd.Parameters.AddWithValue("@date", date);
          sqlcmd.ExecuteNonQuery();
      }
  }
  </code></pre>
  
  <p>Note: I'm using ExcelDataReader.</p>
  
  <p>How would I fix the issue of duplicate data being inserted into the database from the code?</p>