title: Inserting values into Database.mdf C#
body: <p>I've been trying to insert values to a <code>Database.mdf</code> SQL Server database file via datagridView from a few textboxes before loading them in to a Chart, but first it was returning this error:</p>
  
  <blockquote>
    <p>System.Data.SqlClient.SqlCommand' does not contain a definition for
    'Open' and no extension method 'Open' accepting a first argument of
    type 'System.Data.SqlClient.SqlCommand' could be found (are you
    missing a using directive or an assembly reference?)
    C:\Users\DELL\Documents\Visual Studio
    2012\Projects\WindowsFormsApplication6\WindowsFormsApplication6\Form1.cs
    65 44 WindowsFormsApplication6</p>
  </blockquote>
  
  <p>But then that error disappeared (without me changing any code, but merely recompiling it) and now this function (i.e; <code>sendrow()</code>) is effectively useless, doing absolutely nothing, not even giving an error. I suppose if it managed to write it to database, I could have seen it on datagridView on Form.</p>
  
  <pre><code>SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
  csb.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\DELL\Documents\Visual Studio 2012\Projects\WindowsFormsApplication6\WindowsFormsApplication6\Database1.mdf;Integrated Security=True";
  
  using (SqlConnection conn = new SqlConnection(csb.ConnectionString))
  { 
      conn.Open();
  
      using (SqlCommand cmd = new SqlCommand("INSERT INTO Stocks (Open, High, Low, Close, Day) VALUES (@Open, @High, @Low, @Close, @Day)"))
      {
          cmd.CommandType = CommandType.Text;
          cmd.Connection = conn;
  
          // cmd.Parameters.Add(new SqlParameter("@Open", SqlDbType.VarChar, 40));    //using this way "The variable name '@Open' has already been declared. Variable names must be unique within a query batch or stored procedure."
          // cmd.Parameters.AddWithValue("@Open", textBox13.Text);
          cmd.Parameters.AddWithValue("@Open", textBox13.Text);          
          cmd.Parameters.AddWithValue("@High", textBox14.Text);
          cmd.Parameters.AddWithValue("@Low", textBox15.Text);
          cmd.Parameters.AddWithValue("@Close", textBox16.Text);
  
          cmd.ExecuteNonQuery();   // Incorrect syntax near the keyword 'Open'.
      }
  
      stocksTableAdapter.Update(database.Stocks); //LINE***added later but still getting "Incorrect syntax near the keyword 'Open'."
  }
  </code></pre>
  
  <p>In the database, a table added called <code>Stocks</code>, with 5 columns (<code>Id, Open, High, Low, Close</code>). I apologise if I'm missing something obvious, as I'm fairly new to SQL Server. The database is created as a service-based database and there is no value given other than creating <code>Open, High, Low, Close, Day</code> columns and defining their inputs as <code>Decimal(18,4)</code> for <code>Open, High, Low, Close</code> and <code>Datetime</code> for <code>Day</code> (but this is not deed any value in the code yet)</p>