Commiting db changes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What am I missing here? Based on what the help files tell me, it seems like
my code should look like this:

libraryTableAdapter1.Fill(library1._Library);
libraryTableAdapter1.Insert(result, 1, 0, 0, 0, 0, "",
"", "", "", 2000);
libraryTableAdapter1.Update(library1._Library);
library1._Library.AcceptChanges();

When my program finishes, however, there is nothing new. The row was never
added to the actual db.

libraryTableAdapter1 is a TableAdapter
library1 is a DataSet
result is a string

PS: This is in VS2005.
 
Why would you involve the TableAdapter in the Insert operation? I would
think that you would Insert into a particular DataTable within your
DataSet, then call TableAdapter.Update to write that change back to the
database.
 
Because that is what
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_raddata/html/012c5924-91f7-4790-b2a6-f51402b7014b.htm
from the VS2005 help file seems to be telling me to do.
 
Hi,

mmxbass said:
What am I missing here? Based on what the help files tell me, it seems
like
my code should look like this:

libraryTableAdapter1.Fill(library1._Library);
libraryTableAdapter1.Insert(result, 1, 0, 0, 0, 0, "",
"", "", "", 2000);
libraryTableAdapter1.Update(library1._Library);
library1._Library.AcceptChanges();

When my program finishes, however, there is nothing new. The row was never
added to the actual db.

It should either be :
libraryTableAdapter1.Fill(library1._Library);
library1._Library.Add_LibraryRow( ... );
libraryTableAdapter1.Update(library1._Library );
- or -
libraryTableAdapter.Insert( ... );

So you shoudln't confuse them. Offcourse it doesn't really explain why
TableAdapter.Insert didn't work. What DB are you using ?

HTH,
Greetings
 
I'm using an MS access table that I brought in to the project with the add
new data source wizard. Reading the DB works a-ok. Writing is the big problem
here. Nothing seems to take.
 
Hi,

mmxbass said:
I'm using an MS access table that I brought in to the project with the add
new data source wizard. Reading the DB works a-ok.

If the .mdb is part of the project (visible in solution explorer) then it
will (most likely) be copied to the bin\debug folder when you execute the
application from within vs. The application will use the .mdb in the
bin\debug folder. So the next time your app runs vs overwrites the .mdb and
your previous made changes are lost.

One thing you can do is open App.config file, look for ConnectionString and
change "|DataDirectory|\yourdb.mdb" into "..\..\yourdb.mdb". This way it
will directly use the .mdb that is in the project diectory (instead of of a
new copy).


HTH,
Greetings
 
<h1>??!?! 0_o</h1>
I can't belive I didn't notice that. You're totally right. The origional
code actually does work fine. Visual studio just overrides it with the
origional file every time I rerun the program.

Thank you so much.
 
Back
Top