Another UpdateDataSet Question...

Topics: Data Access Application Block
Feb 15, 2010 at 2:52 PM

First, thank you for your time.

I believe I am following the examples correctly, but no matter what I try I can’t seem to get UpdateDataSet to work.  It bombs in Database.cs on line 543 with exception “Value cannot be null.  Parameter name:  dataTable.”
int rows = adapter.Update(dataSet.Tables[tableName]);

Initially I get a DataSet and populate a spreadsheet control.  I change a single value within the spreadsheet and hit my save button.  To aid in the debugging process, I immediately get the dataset from the spreadsheet and write this dataset out to disk in xml format.  Sure enough the xml shows the change I made in the spreadsheet.  To make debugging simpler, I am starting with only trying to do an update, no inserts or deletes at this time.  Here is the code:

' The mdb is a member variable withing the class.
mdb = DatabaseFactory.CreateDatabase(connectionStringKey)

' Some examples include the @ sign and some examples don't.  I have tried it both ways and it still bombs.
Dim dbcUpdate As System.Data.Common.DbCommand = db.GetStoredProcCommand("AccountUpdate")
mdb.AddInParameter(dbcUpdate, "@AccountId", DbType.Int32, "AccountId", DataRowVersion.Current)
mdb.AddInParameter(dbcUpdate, "@Name", DbType.String, "Name", DataRowVersion.Current)
mdb.AddInParameter(dbcUpdate, "@Type", DbType.String, "Type", DataRowVersion.Current)
mdb.AddInParameter(dbcUpdate, "@Server", DbType.String, "Server", DataRowVersion.Current)

'The next line bombs with:  Value cannot be null. Parameter name: dataTable.
mdb.UpdateDataSet(ds, “Accounts”, Nothing, dbcUpdate, Nothing, _ Microsoft.Practices.EnterpriseLibrary.Data.UpdateBehavior.Standard)
ds.AcceptChanges()          'Do I need this line?

As a second question, which objects within the DAAB need to be Disposed?

Thank you very much for your time,



Feb 16, 2010 at 3:01 AM

I'm guessing there is no "Accounts" data table in your dataset that's why it is complaining about a null dataTable parameter.  When you populate a dataset by using a DbCommand, the naming it uses for each data table is, "Table", "Table1", "Table2", and so on.

As for your second question, what really needs to be disposed are the instances of DbDataReader as they carry with them an open connection.  You could also dispose DbCommand objects but it's not as critical as with the DbDataReader objects as their connections are automatically being closed as soon as the various Execute methods have been executed on them (and will be later handled by the GC). 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc. 

Feb 16, 2010 at 7:50 AM

First, thank you for responding.

Very good, I am populating my dataset with a DbCommand.  Just before the UpdateDataSet call, I set a breakpoint and looked at the properties of the dataset.  I didn't see "Table" or "Table1" etc., but I suspect you are right anyway.  Is the fix as simple as finding the necessary property and setting a new value?  And do you happen to know which property to set or how to fix this? 

Again, thank you.



Feb 16, 2010 at 9:27 AM
Edited Feb 16, 2010 at 9:29 AM

Yes, a datatable has a TableName property.  But you must of course know which is the correct datatable in the dataset you need to change the name.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.