Typed Dataset Problem

  • Thread starter Thread starter Bryce
  • Start date Start date
B

Bryce

Using ASP.NET and C# (Visual Studio 2005). I generated a Typed DataSet.
I run the following code, but don't get any errors, but it doesn't
appear to be updating the database. (I've stepped through the code to
ensure it is hitting the code):

// Begin Code
DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter adapter =
new DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter();

DirectoryListing.DIRECTORY_LISTINGDataTable table = adapter.GetData();
DirectoryListing.DIRECTORY_LISTINGRow dataRow =
table.NewDIRECTORY_LISTINGRow();

dataRow.SomeNumber = 345;

table.AddDIRECTORY_LISTINGRow(dataRow);
table.AcceptChanges();
adapter.Update(table);

// End code

Anything obvious what I'm doing wrong?

Thanks
 
Bryce said:
Using ASP.NET and C# (Visual Studio 2005). I generated a Typed DataSet.
I run the following code, but don't get any errors, but it doesn't
appear to be updating the database. (I've stepped through the code to
ensure it is hitting the code):

// Begin Code
DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter adapter =
new DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter();

DirectoryListing.DIRECTORY_LISTINGDataTable table = adapter.GetData();
DirectoryListing.DIRECTORY_LISTINGRow dataRow =
table.NewDIRECTORY_LISTINGRow();

dataRow.SomeNumber = 345;

table.AddDIRECTORY_LISTINGRow(dataRow);
table.AcceptChanges();
adapter.Update(table);

// End code

Anything obvious what I'm doing wrong?

Thanks

Reverse these two lines from:

table.AcceptChanges();
adapter.Update(table);

to:

adapter.Update(table);
table.AcceptChanges();

and then give it a shot. Basically, when you've called 'AcceptChanges',
there are no changes to be updated when update is called because the
datarowstate will be set to current. In order to verify that an update is
taking place, you can do a number of things but the easiest is to register
the adapter's row_updating event and trace the output to make sure it's
firing.

Drew
 
Bryce said:
Using ASP.NET and C# (Visual Studio 2005). I generated a Typed DataSet.
I run the following code, but don't get any errors, but it doesn't
appear to be updating the database. (I've stepped through the code to
ensure it is hitting the code):

// Begin Code
DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter adapter =
new DirectoryListingTableAdapters.DIRECTORY_LISTINGTableAdapter();

DirectoryListing.DIRECTORY_LISTINGDataTable table = adapter.GetData();
DirectoryListing.DIRECTORY_LISTINGRow dataRow =
table.NewDIRECTORY_LISTINGRow();

dataRow.SomeNumber = 345;

table.AddDIRECTORY_LISTINGRow(dataRow);
table.AcceptChanges();
adapter.Update(table);

// End code

Anything obvious what I'm doing wrong?

Thanks

Reverse these two lines from:

table.AcceptChanges();
adapter.Update(table);

to:

adapter.Update(table);
table.AcceptChanges();

and then give it a shot. Basically, when you've called 'AcceptChanges',
there are no changes to be updated when update is called because the
datarowstate will be set to current. In order to verify that an update is
taking place, you can do a number of things but the easiest is to register
the adapter's row_updating event and trace the output to make sure it's
firing.

Drew
 
Back
Top