I have problem when i try to save changes in database. Am geting exception
Value cannot be null
Check my code am not shure what is happening
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);
}
}
}
StackTrace
at System.Data.Common.DbDataAdapter.Update(DataTable dataTable)
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)
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& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
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
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
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()
adapter.Update(dt);
– SlaigrupeArtikalaGrid.DataSource = bindingSource1;
– SlaibindingSource1.DataSource
to anything. For examplebindingSource1.DataSource = dt;
– SlaibindingSource1.DataSource = dt;
insideGetData
method and again am getting the some – Ivan