Cannot seem to update underlying DataAdapter with Values in Datagrid

  • Thread starter Thread starter gmartin
  • Start date Start date
G

gmartin

I'm new to .NET, but certainly not new to development work. I've been
trying everything I can think of to get the worlds simplest
implementation of a DataGrid to actually update the changes back to
the database. I've been working on it for two days and I can't seem
to get my "Hello World" datagrid implementation to work.

ANY guidance would be most appreciated. I've tried numerous code
solutions, but none commit any changes back to the database and none
give any sort of error messages.

I simply plopped a datagrid on the form, answered the dialog about
what datasource to use, chose the insert, update, delete checkboxes,
etc... and thought that would be enough. Obviously, it wasn't.
Then, I found all kinds of examples about using HasChanged to
determine if changes had been made and then dataAdapter.Update to
commit the changes. Nothing worked.

I can't believe it's this hard. I know I'm doing something wrong, but
for the life of me I can't figure out what it is. I'll be happy to
post whatever code snippets are needed or even the entire project if
it will help.

Thanks in advance.
 
I can't believe it's this hard. I know I'm doing something wrong, but
for the life of me I can't figure out what it is. I'll be happy to post
whatever code snippets are needed or even the entire project if it will
help.

You are not alone with that idea. This will commit everything that has
updated.

var BindingSourcesQuery =
from Component bindingSources in this.components.Components
where bindingSources is BindingSource
select bindingSources;

foreach (BindingSource bindingSource in BindingSourcesQuery)
{
bindingSource.EndEdit();
}


tableAdapterManager.UpdateAll(yourDataset);
 
My bad. I didn't mention that I was working in VB.NET. I pasted the
code into the FormClosing event and VB didn't like it at all. Looks
like it might be C. Do you have the VB equivalent?

Thank you so much for your help.
 
I found my answer finally and I'm probably more ticked off now than
before I started this cursed experiment. Found this little tidbit in
another forum...

++++++++++++++++++++++++++++++++++++++++++++++
In addition:
Select/click your database file in Solution Explorer
-> Properties Pane
-> change the "copy to ouput directory" to "copy if newer"
++++++++++++++++++++++++++++++++++++++++++++++

Did that and everything started working like a champ. What bugs me is
that this means that probably every single permutation that I tried
over the past two days was probably working perfectly. I just
couldn't tell because I kept looking at an older copy of the database.

AAAAAAAAAAAAGGGGGGGGGGGGGHHHHHHHHHHHHHHHHH!!!

Anyway, thanks for trying to help. I really do appreciate it.
 
Back
Top