Strongly typed datasets and schema changes
Asked Answered
P

2

6

I have a project which uses strongly typed datasets.

Let's assume I want to change the database schema of the database used by this application. I have a table named Country and I want to add a new column named "IsADemocracy" (that's an example) of the SQL Server datatype BIT.

Now, how do I update the strongly typed dataset so that I can use this new field in the application?

I've tried adding the column in the Country table on the dataset, gave it the type of boolean and mapped its "Source" property to "IsADemocracy".

I can access the field in the application, give it a value, etc, but the underlying queries made by the table adapter have not been updated to reflect this change. They are as they were before I added this column in the strongly typed dataset. I hoped what I did would be enough but it does not seem to be the case.

Should I regenerate the strongly datasets classes somehow? If so, how and what are the implications?

I could probably delete the Country table in the Dataset designer, and redrop it from the Server Explorer, but I have customer queries on it and I don't want to lose them.

Thanks.

Perigynous answered 4/8, 2010 at 17:20 Comment(0)
V
0
  1. First, make sure you have a backup

  2. Right click on the .xsd node in Solution Explorer and select "Run Custom tool"

But be careful with your Custom Queries. They have a tendency to disappear without warning. Not always.

This is one good reason to fill in those queries form the partial class 'main' file.

Volute answered 4/8, 2010 at 17:42 Comment(4)
Sorry, tried the Run custom tool before and it doesn't seem to update the classes. I also tried to rename the table and table adapter in the designer as this website suggests (devfuel.com/2007/03/…), but it doesn't get updated.Perigynous
Yes, you're right. The custom tool (WSDL) does not read the db-schema again. You'll have to re-build every (changed) adapter again (right-click, configure). Note that that is a sure way to lose customizations to the CRUD queries.Volute
Typed Datasets are just not very nice when the schema changes.Volute
Indeed. This is the best I could find: vbcity.com/forums/p/132685/566940.aspx#566940 If someone has a better way, I would be glad to hear it.Perigynous
C
2

Another suggestion - right click on the Table's representation in the designer i.e the xsd, and use the Add Option, to add a Column. Once you have the column, you need to set its properties as by default a new column gets added as a string. Doing it this way means you retain any custom queries etc that have been added earlier.

This allows you to add columns, obviously deleting is more straightforward.

Cordero answered 31/5, 2011 at 19:18 Comment(0)
V
0
  1. First, make sure you have a backup

  2. Right click on the .xsd node in Solution Explorer and select "Run Custom tool"

But be careful with your Custom Queries. They have a tendency to disappear without warning. Not always.

This is one good reason to fill in those queries form the partial class 'main' file.

Volute answered 4/8, 2010 at 17:42 Comment(4)
Sorry, tried the Run custom tool before and it doesn't seem to update the classes. I also tried to rename the table and table adapter in the designer as this website suggests (devfuel.com/2007/03/…), but it doesn't get updated.Perigynous
Yes, you're right. The custom tool (WSDL) does not read the db-schema again. You'll have to re-build every (changed) adapter again (right-click, configure). Note that that is a sure way to lose customizations to the CRUD queries.Volute
Typed Datasets are just not very nice when the schema changes.Volute
Indeed. This is the best I could find: vbcity.com/forums/p/132685/566940.aspx#566940 If someone has a better way, I would be glad to hear it.Perigynous

© 2022 - 2024 — McMap. All rights reserved.