views:

1844

answers:

4

I've got a DataSet in VisualStudio 2005. I need to change the datatype of a column in one of the datatables from System.Int32 to System.Decimal. When I try to change the datatype in the DataSet Designer I receive the following error:

"Property value is not valid. Cannot change DataType of a column once it has data."

From my understanding, this should be changing the datatype in the schema for the DataSet. I don't see how there can be any data to cause this error.

Does any one have any ideas?

+1  A: 

Since filled Datatables do not entertain a change in the schema a workaround can be applied as follows:

  1. Make a new datatable

  2. Use datatable's Clone method to create the datatable with the same structure and make changes to that column

  3. In the end use datatable's ImportRow method to populate it with data.

HTH

Codeslayer
+1  A: 

@Codeslayer - That is not going to help. I'm trying to change the datatype inside of the DataSet designer before I compile my code. The dataset has not yet been filled since I'm not trying to make this change during runtime. I'm still at a loss as to why I'm getting the error message since the dataset has no data.

I have found a work around. If I delete the data column and add it back with the different data type, then it will work.

firedfly
I have run into the same problem. Strange - can't change it in the designer. Looks like a bug...
aSkywalker
+1  A: 

I get the same error but only for columns with its "DefaultValue" set to any value (except the default DBNull). So the way I got around this issue was:

  1. Column DefaultValue : Type in DBNull enclosed in brackets
  2. Save and reopen the dataset
Are
A: 

Thanks for the answer, NOTE: use angle brackets: "< DBNull >" (without the spaces)