Typed Dataset Problem

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
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top