title: MySQL Update using DataGridView
body: <p>This goes to the genius out there let's see if YOU can help me.</p>
  
  <pre><code>Imports System
  Imports System.Data
  
  ' Version 6.5.4.0 Runtime v2.0.50727
  Imports MySql.Data.MySqlClient
  
  Public Class MainForm
  
    ' Config - Main. 
    Private db_host As String = ""
    Private db_username As String = ""
    Private db_userpass As String = ""
    Private db_catalog As String = ""
    Private db_port As String = "3306"
  
    ' Config - Specific Table.
    Private db_specific_table As String = "SF6SETUP"
  
    ' Config - Other.
    Private DS As DataSet
    Private DA As MySqlDataAdapter
    Private BS As BindingSource
  
    ' ***
    '
    ' ***
    Private Sub My_Init()
  
      Dim conn As String = "Data Source = " &amp; db_host &amp; ";Initial Catalog=" &amp; db_catalog &amp; "; uid=" &amp; db_username &amp; ";password=" &amp; db_userpass
      Dim myConnection As New MySqlConnection(conn)
      Dim cmd As String = "SELECT * FROM " &amp; db_specific_table
  
      DA = New MySqlDataAdapter(cmd, myConnection)
      ' This line of code to generate update commands automatically.
      ' This update method of would not work without this line of code. 
      Dim MySQLCommandBuilder As New MySqlCommandBuilder(DA)
  
      myConnection.Open()
  
      DS = New DataSet()
      DA.Fill(DS, "MyTable")
  
      BS = New BindingSource
      BS.DataSource = DS.Tables(0)
  
      Dim BN As BindingNavigator = New BindingNavigator()
      BN.BindingSource = BS
      DataGridView.DataSource = BS
  
    End Sub
  
    ' ***
    '
    ' ***
    Private Sub MainForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
  
      My_Init()
  
    End Sub
  
    Private Sub DataGridView_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView.KeyPress
      BS.EndEdit()
      DA.Update(DS, "MyTable")
    End Sub
  End Class
  </code></pre>
  
  <p>There is an error:</p>
  
  <p>An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll</p>
  
  <p>Additional information: Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.</p>
  
  <p>This code works EXCEPT no changes saved to MySQLDatabase!!!
  Please, help me solve this. </p>
  
  <p>Thank you,</p>
  
  <p>Mike</p>