title: Add path to SQL Server using c#
body: <p>I tried adding a file path to SQL Server from a C# application and that this exception that appeared : </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.Data.SqlClient.SqlException'
    occurred in System.Data.dll</p>
    
    <p>Additional information: Incorrect syntax near
    'C:\Users\Misfen\Desktop\image.jpg'.</p>
  </blockquote>
  
  <pre><code>private void button9_Click(object sender, EventArgs e)
  {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "JPG FILES (*.jpg)|*.jpg|JPEG FILES (*.jpeg)|*.jpeg|PNG FILES (*.png)|*.png";
  
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          string picpath = dlg.FileName.ToString();
          listBox2.Items.Add(picpath);
  
      }
  }
  
  private void button5_Click(object sender, EventArgs e)
  {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "JPG FILES (*.jpg)|*.jpg|JPEG FILES (*.jpeg)|*.jpeg|PNG FILES (*.png)|*.png|PDF FILES (*.pdf)|*.pdf|DOC FILES (*.doc)|*.doc";
  
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          string picpath = dlg.FileName.ToString();
          textBox4.Text = picpath;
      }
  }
  
  private void button6_Click(object sender, EventArgs e)
  {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "JPG FILES (*.jpg)|*.jpg|JPEG FILES (*.jpeg)|*.jpeg|PNG FILES (*.png)|*.png|PDF FILES (*.pdf)|*.pdf|DOC FILES (*.doc)|*.doc";
  
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          string picpath = dlg.FileName.ToString();
          textBox5.Text = picpath;
      }
  }
  
  private void button7_Click(object sender, EventArgs e)
  {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "JPG FILES (*.jpg)|*.jpg|JPEG FILES (*.jpeg)|*.jpeg|PNG FILES (*.png)|*.png";
  
      if (dlg.ShowDialog() == DialogResult.OK)
      {
          string picpath = dlg.FileName.ToString();
          listBox1.Items.Add(picpath);
      }    
  }
  </code></pre>
  
  <p>C# code : </p>
  
  <pre><code>String req = "insert into dommage_materiel values(" + textBox1.Text + ",'" + richTextBox2.Text + "','" + richTextBox1.Text + "','" + textBox3.Text + "','" + dateTimePicker1.Value + "','" + richTextBox3.Text + "','" + textBox2.Text + "','" + textBox4.Text.ToString() + "','" + textBox5.Text.ToString() + "'";
  
  SqlCommand cmd = new SqlCommand(req, cnx);
  
  cnx.Open();
  cmd.ExecuteNonQuery();
  cnx.Close();
  
  for (int i = 0; i &lt; listBox1.Items.Count; i++)
  {
      SqlCommand cmd2 = new SqlCommand("insert into photo_domage values ('"+textBox1.Text+"','"+listBox1.Items[i].ToString()+"')", cnx);
  
      cnx.Open();
      cmd2.ExecuteNonQuery();
      cnx.Close();
  }
  
  for (int i = 0; i &lt; listBox2.Items.Count; i++)
  {
      SqlCommand cmd2 = new SqlCommand("insert into fichier_domage values ('" + textBox1.Text + "','" + listBox1.Items[i].ToString() + "')", cnx);
  
      cnx.Open();
      cmd2.ExecuteNonQuery();
      cnx.Close();
  }
  </code></pre>
  
  <p>SQL code : </p>
  
  <blockquote>
  <pre><code>create table dommage_materiel
  (
       num varchar(30) primary key,
       object_sistre varchar(500),
       discription varchar(1500),
       lieux varchar(100), 
       date_inci date, 
       domage varchar(50), 
       estimation varchar(30), 
       pv nvarchar(150), 
       facture nvarchar(1500)
  )
  
  create table photo_domage
  (
       num varchar(30) foreign key references dommage_materiel (num), 
       ref nvarchar(1500)
  )
  
  create table fichier_domage 
  (
       num varchar(30) foreign key references dommage_materiel (num),
       ref nvarchar(1500)
  )
  </code></pre>
  </blockquote>