title: VB.NET: Generating MySQL Query Using Variables
body: <p>I have written the code below to update my table, but it doesn't work.</p>
  
  <pre><code>sqlstr = "UPDATE Student SET " &amp; S &amp; " = @field1, " &amp; L &amp; " = @field2, " &amp; R &amp; " =@field3, " &amp; W &amp; "=@field4 WHERE Code='" &amp; StdID &amp; "'"
  DBCmd = New MySql.Data.MySqlClient.MySqlCommand(sqlstr, DBConn)
  With DBCmd
          .Parameters.AddWithValue("@field1", CB_S.SelectedItem)
          .Parameters.AddWithValue("@field2", CB_L.SelectedItem)
          .Parameters.AddWithValue("@field3", CB_R.SelectedItem)
          .Parameters.AddWithValue("@field4", CB_W.SelectedItem)
      End With
      DBCmd.Dispose()
  </code></pre>
  
  <p>Where S, L, R and W are strings: S1, L1, R1, W1.
  And StdID is an integer. CB_S, CB_L, CB_R and CB_W are comboboxes.</p>
  
  <p>Could anyone tell me what is wrong?</p>