title: ID is neither a DataColumn nor a DataRelation for Table
body: <p>I wanted to delete single data in the database based on their "ID" (Auto Number). But, when i wanted to delete, here is the error that i getting:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.ArgumentException' occurred in
    System.Data.dll</p>
  </blockquote>
  
  <p>Additional information: ID is neither a DataColumn nor a DataRelation for table Table."</p>
  
  <p>Here is the code that i am using:</p>
  
  <pre><code>private void DeleteDatabase(object sender, EventArgs e)
          {
              DataTable _dt = (DataTable)dataGridView1.DataSource;
  
              if (_dt.DefaultView.Count &gt; 0)
              {
                  int rowNum = dataGridView1.CurrentRow.Index;
                  int id = Convert.ToInt32(_dt.DefaultView[rowNum]["ID"]);
                  _dt.DefaultView[rowNum].Delete();
  
                  using (OleDbConnection conn = new OleDbConnection(connectionString))
                  {
                      string query = "DELETE FROM [Table] WHERE [ID] = @ID";
                      conn.Open();
  
                      using (OleDbCommand cmd = new OleDbCommand(query, conn))
                      {
                          cmd.Parameters.AddWithValue("@ID", id);
                          cmd.ExecuteNonQuery();
                      }
  
                      conn.Close();
                  }
              }
  
              else
              {
                  if (_choice.comboBox1.Text == "English")
                  {
                      System.Media.SoundPlayer _sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                      _sounds.Play();
                      MessageBox.Show("There is no Data in the Selected Row!", "Error");
                      return;
                  }
              }
  
              if (_choice.comboBox1.Text == "English")
              {
                  System.Media.SoundPlayer _sounds = new System.Media.SoundPlayer(@"C:\Windows\Media\Windows Exclamation.wav");
                  _sounds.Play();
                  MessageBox.Show("Deleted Successfully!", "Deleted");
              }
          }
  </code></pre>
  
  <p>Here is the database view in the datagridview on my system:</p>
  
  <p><img src="https://i.stack.imgur.com/ZuYyf.png" alt="enter image description here"></p>
  
  <p><strong>Updated:</strong></p>
  
  <p>Here is the code of view database:</p>
  
  <p>If i didn't include <code>[ID]</code> in the <code>SELECT</code> query in the <code>ViewDatabase()</code>, it will error, but if i include that, and when i click <code>Print Preview</code>, it will show the <code>ID</code> column as the image below.</p>
  
  <pre><code>private void ViewDatabase(object sender, EventArgs e)
          {
              using (OleDbConnection conn = new OleDbConnection(connectionString))
              {
                  string query = "SELECT * FROM [Table]";
  
                  conn.Open();
  
                  using (OleDbDataAdapter _adapter = new OleDbDataAdapter(query, conn))
                  {
                      _ds.Clear();
                      _adapter.Fill(_ds, "Table");
                      dataGridView1.DataSource = null;
                      dataGridView1.Refresh();
                  }
  
                  dataGridView1.DataSource = _ds.Tables[0];
  
                  this.dataGridView1.Columns["ID"].Visible = false;
  
                  conn.Close();
              }
          }
  </code></pre>
  
  <p>I am aware that if i choose <code>Product Code</code> rather than <code>ID</code> to delete the data, it will be more possible, but if let's say there are 2 same <code>Product Code</code> and when i click delete, both data will be deleted, because it is same <code>Product Code</code>. </p>
  
  <p>But, i also wanted to hide the <code>ID</code> whenever i click <code>Print Preview</code>, i don't want to show any <code>ID</code> when i click <code>Print Preview</code>. This image below shows the <code>Print Preview</code> got <code>ID</code> column, where in the view database on the system there is no <code>ID</code> visible.</p>
  
  <p><img src="https://i.stack.imgur.com/5B9Re.png" alt="enter image description here"></p>
  
  <p>my question is: 
  how do i delete the database using <code>ID</code>, but in the <code>ViewDatabase()</code> the <code>ID</code> column will not be visible to users and whenever i click <code>Print Preview</code>, the <code>ID</code> will not be visible as well. The <code>ID</code> will only be visible to the system (The <code>ID</code> on <code>DeleteDatabase()</code> will run and the <code>ID</code> on <code>PrintPreview() and ViewDatabase()</code> will not be visible to users)</p>
  
  <p>i apologize if i am making you confuse.</p>
  
  <p>Any help? Thank you!</p>