title: Oledb Insert statement using parameters
body: <p>How do I insert into parameters from different tables using OleDB?</p>
  
  <p>I have 3 tables:
  1. itemTbl
  2. crateTbl
  3. contentTbl</p>
  
  <p>itemTbl has: itemID, itemName, itemDesc
  crateTbl has: crateID, crateName
  contentTbl has: crateID, itemID, qty</p>
  
  <p>contentTbl is the contents of the crate and the qty of each</p>
  
  <p>I need it to select values in different tables I use <code>WHERE</code>. I have tried a similar code using a local db and service based db and they allow me, but OleDB doesn't let me use VALUES((SELECT))....</p>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>System.Data.OleDb.OleDbException: 'Query input must contain at least one table or query.</p>
  </blockquote>
  
  <p>My code:</p>
  
  <pre><code>cmd.Dispose();
  
  cmd.CommandText = @"INSERT INTO contentTbl(crateID,itemID,qty) VALUES((SELECT crateTbl.crateID FROM crateTbl WHERE crateTbl.crateID=?),(SELECT itemTbl.itemID FROM itemTbl WHERE itemTbl.itemID = ?), ?)";
  cmd.Connection = con;
  
  cmd.Parameters.Add(new OleDbParameter("crateID", txtCrate.Text));
  cmd.Parameters.Add(new OleDbParameter("itemID", txtItem.Text));
  cmd.Parameters.Add(new OleDbParameter("qty", txtQty.Text));
  
  con.Open();
  cmd.ExecuteNonQuery();
  con.Close();
  
  MessageBox.Show("Done!");
  
  da.SelectCommand = new OleDbCommand("SELECT * FROM contentTbl", con);
  da.Fill(dt);
  
  dgvContent.DataSource = dt;
  </code></pre>