title: How to insert into a Service-based Database
body: <pre><code>public partial class Form1 : Form
  {
      SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Dimmer\Documents\Visual Studio 2013\Projects\Manage components\Manage components\Database1.mdf;Integrated Security=True");
  
      SqlCommand cmd = new SqlCommand();
      SqlDataReader dr;
  
      public Form1()
      {
          InitializeComponent();
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
          cmd.Connection = cn;
          loadlist();
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          if (txtid.Text != "" &amp; txtname.Text != "")
          {
              cn.Open();
              cmd.CommandText = "insert into info (id,name) values ('"+txtid.Text+"'.'"+txtname.Text+"')";
              cmd.ExecuteNonQuery();
              cmd.Clone();
              MessageBox.Show("Record instered!");
              txtid.Text = "";
              txtname.Text = "";
              loadlist();
          }
      }
  }
  </code></pre>
  
  <p>I am new to C# and I have been trying for some hours with a insert code to a service-based database. I have tested the connection to it and it works.</p>
  
  <p>I got this error message: </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll</p>
    
    <p>Additional information: Incorrect syntax near 'xxxx'. </p>
  </blockquote>
  
  <p>Where <code>xxxx</code> is what I insert into my 2nd textbox. The code stops at </p>
  
  <pre><code>cmd.ExcecuteNonQuery();
  </code></pre>
  
  <p>I have been searching for an answers for hours, I believe there is something wrong with the database.</p>
  
  <p>Sorry if this code looks ugly, but I had some problems with spaces :P</p>