0

So, I made a database in SQL Server Express 2014. After that, from Visual Studio 2015 Community, I make a new project, and then I add new data source, and then choosing Database, and then Dataset, and then choosing all tables and views in the database.

The problem is, after I made some changes to the database from the SQL Server (either changing a column name, or column data type, or manually adding some data for testing), the changes are not pushed back to my project in Visual Studio, it also says error table name from the renamed Column Name.

Any idea how to automatically set the changes made in SQL Server to the Visual Studio side?

3
  • For all I know you have to do it yourself. Commented Jan 23, 2016 at 8:37
  • updated my answer to explain how to update the schema in VS and to say why EF is probably a better solution Commented Jan 23, 2016 at 9:14
  • If you are manipulating your Database via C#, I would recommand you to use the ObjectDataSource class. Simply bind the ODS-object to the ItemsSource of your table (etc.) and if you update your table with the ODS-object, your database and table will automatically refresh (if done right): msdn.microsoft.com/en-us/library/… Commented Jan 23, 2016 at 9:20

1 Answer 1

1

DataSets in .NET do not automatically sync their schemas with SQL, so changes made in SQL will not be reflected in Visual Studio. To see the changes in Visual Studio you need to:

  • open the .xsd file for your dataset in design view by double clicking on it
  • then delete the table that has changed from the schema
  • then open the server explorer
  • find your data connection
  • expand the tables node
  • and drag the table back onto the xsd designer.

That's obviously a nuisance to do, so you could use Entity Framework to automate this process.

Entity Framework allows you to work in a few different ways:

  • You can define tables on the fly from your code, and EF can automatically produce migrations to update the database schema to match your changes, e.g. if you rename a class property in Visual Studio it will change the database schema. That's called 'code first'.
  • Or, you can design the database and have Entity Framework generate code, which is unsurprisingly called 'database first'.

This is the official site for Entity Framework.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for mentioning EF. Doesn't realize that EF was called Linq to Sql (when I'm in college), which is exactly what I looking for (lost my college files lols)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.