title: c# datagridview update Value cannot be null
body: <p>I have problem when i try to save changes in database. Am geting exception</p>
  
  <blockquote>
    <p>Value cannot be null</p>
  </blockquote>
  
  <p>Check my code am not shure what is happening</p>
  
  <pre><code>public class GrupeArtikala : Form, IGrupeArtikalaView
  {
      #region Properties 
      private DataTable dt = new DataTable();
      private DataSet ds = new DataSet();
      private BindingSource bindingSource1 = new BindingSource();
  
      private MySqlConnection conn;
      private MySqlDataAdapter adapter;
  
  
      #endregion
  
  
      private void GrupeArtikala_Load(object sender, EventArgs e)
      {
          grupeArtikalaGrid.DataSource = bindingSource1;
          GetData("SELECT * FROM grupe");
      }
  
      private void saveToolStripButton_Click(object sender, EventArgs e)
      {
          // Update the database with the user's changes.
          adapter.Update((DataTable)bindingSource1.DataSource);
      }
  
      private void GetData(string selectCommand)
      {
          try
          {
              conn = new MySqlConnection(Properties.Settings.Default.ConnectionString);
  
              adapter = new MySqlDataAdapter(selectCommand, conn);
  
              // Create a command builder to generate SQL update, insert, and
              // delete commands based on selectCommand. These are used to
              // update the database.
              MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder(adapter);
  
              // Populate a new data table and bind it to the BindingSource.
              dt = new DataTable();
              dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
              adapter.Fill(dt);
              grupeArtikalaGrid.DataSource = dt;
  
              // Resize the DataGridView columns to fit the newly loaded content.
              grupeArtikalaGrid.AutoResizeColumns(
                  DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
          }
          catch (MySqlException ex)
          {
              MessageBox.Show(ex.Message);
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/zIrkh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zIrkh.png" alt="enter image description here"></a></p>
  
  <p><strong>StackTrace</strong></p>
  
  <blockquote>
    <p>at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)<br>
    at MVPLearing.GrupeArtikala.saveToolStripButton_Click(Object sender,
    EventArgs e) in
    E:\Radni\C#\WinForms-Ucenje\MVPLearing\MVPLearing\GrupeArtikala.cs:line
    308    at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key,
    EventArgs e)    at
    System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)    at
    System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)    at
    System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)<br>
    at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs
    e, ToolStripItemEventType met)    at
    System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e,
    ToolStripItemEventType met)    at
    System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)    at
    System.Windows.Forms.Control.WmMouseUp(Message&amp; m, MouseButtons
    button, Int32 clicks)    at
    System.Windows.Forms.Control.WndProc(Message&amp; m)    at
    System.Windows.Forms.ScrollableControl.WndProc(Message&amp; m)    at
    System.Windows.Forms.ToolStrip.WndProc(Message&amp; m)    at
    System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&amp; m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&amp;
    m)    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
    hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    at
    System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)<br>
    at
    System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr
    dwComponentID, Int32 reason, Int32 pvLoopData)    at
    System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
    reason, ApplicationContext context)    at
    System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
    reason, ApplicationContext context)    at
    System.Windows.Forms.Application.Run(Form mainForm)    at
    MVPLearing.Program.Main() in
    E:\Radni\C#\WinForms-Ucenje\MVPLearing\MVPLearing\Program.cs:line 19<br>
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
    String[] args)    at System.AppDomain.ExecuteAssembly(String
    assemblyFile, Evidence assemblySecurity, String[] args)    at
    Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br>
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br>
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext
    executionContext, ContextCallback callback, Object state, Boolean
    preserveSyncCtx)    at
    System.Threading.ExecutionContext.Run(ExecutionContext
    executionContext, ContextCallback callback, Object state, Boolean
    preserveSyncCtx)    at
    System.Threading.ExecutionContext.Run(ExecutionContext
    executionContext, ContextCallback callback, Object state)    at
    System.Threading.ThreadHelper.ThreadStart()</p>
  </blockquote>