title: SQL with Visual C#: Incorrect syntax near ''
body: <p>I keep on getting an sql exception error that states: </p>
  
  <blockquote>
    <p>Incorrect syntax near 'Bsc.'. </p>
  </blockquote>
  
  <p>This error happens at the line I have indicated with a comment.</p>
  
  <p><code>'Bsc'</code> is the value of val1 that has been parsed?</p>
  
  <p>I have tried all means to resolve the error but I am not sure what's the problem,</p>
  
  <pre><code>public Marksheet(object val1, object val2, object val3, object val4)
  {
      InitializeComponent();
  
      string connectionString = null;
      SqlConnection conn; 
      connectionString = "Server=localhost\\SQLEXPRESS;Integrated security=SSPI;database=jms";
  
      SqlDataAdapter sda = new SqlDataAdapter("Select s.course_abbreviation, s.course_name, s.month_of_admission, s.year_of_admission from students s where exists (select 1 from units_allocation ua where s.course_abbreviation=ua.'"+val1+"' and s.course_name=ua.'"+val2+"' and s.month_of_admission=ua.'"+val3 +"' and s.year_of_admission=ua.'"+val4+"'", connectionString);
  
      conn = new SqlConnection(connectionString);
      DataTable dt5 = new System.Data.DataTable();
      sda.Fill(dt5);    // Error occurs here
      gridControl1.DataSource = dt5;
  }
  </code></pre>
  
  <p>The sql query is an inner join between students table and units_allocated table.</p>
  
  <p>I am fetching records from students table where the 4 fields are equal...</p>
  
  <p>The above function is in different form and which is called by the following:</p>
  
  <pre><code>object val1;
      object val2;
      object val3;
      object val4;
      private void gridView1_RowClick(object sender, RowClickEventArgs e)
      {
          int rowHandle = e.RowHandle;
          val1 = gridView1.GetRowCellValue(rowHandle, gridView1.Columns[2]);
          val2 = gridView1.GetRowCellValue(rowHandle, gridView1.Columns[3]);
          val3 = gridView1.GetRowCellValue(rowHandle, gridView1.Columns[4]);
          val4 = gridView1.GetRowCellValue(rowHandle, gridView1.Columns[5]);
  
          Marksheet marksheet = new Marksheet(val1, val2, val3, val4);
          marksheet.Show();
      }
  </code></pre>
  
  <p>I want to output a gridview/table in the second form with student records having 4 field values to the one I am clicking.</p>
  
  <p>I am passing column values and expecting records from students table with fields registration_no, first_name, last_name, cat1_marks, cat2_marks, exam_marks and overall_marks.</p>