Insert data and check for duplicate records
<pre><code>            string checkstring = @"SELECT Count(*) FROM Items WHERE itemno = @itemno";  
            string insertstring = @"INSERT INTO Items (itemno, categ, name, quant, price) VALUES (@itemno, @categ, @name, @quant, @price)";  

            SqlConnection myConnection = new SqlConnection(@"Data 

            Source=PC80978273;Initial Catalog=NewUsers;Integrated Security=True");  
            myConnection.Open();  
            SqlCommand cmdAdd = new SqlCommand(insertstring, myConnection);
            SqlCommand cmdCheck = new SqlCommand(checkstring, myConnection);

            int result = (int)cmdCheck.ExecuteScalar();

            if (result &gt; 0)
            {
                MessageBox.Show("Item number already exists.");
            }
            else
            {
                cmdAdd.ExecuteNonQuery();
                MessageBox.Show("Item has been added to the inventory.");
            }

            cmdAdd.Parameters.AddWithValue("@itemno", txtItemNo.Text);
            cmdAdd.Parameters.AddWithValue("@categ", cmbCategory.SelectedItem.ToString());
            cmdAdd.Parameters.AddWithValue("@name", txtName.Text);
            cmdAdd.Parameters.AddWithValue("@quant", txtQuantity.Text);
            cmdAdd.Parameters.AddWithValue("@price", txtPrice.Text);

            myConnection.Close();
</code></pre>

<p>How do I check for a duplicate record (itemno) and add  an error message before inserting data into my database?
An error code is dispayed </p>

<blockquote>
  <p>"must declare the scalar variable "@itemno"</p>
</blockquote>

<p>What is wrong with my code?</p>