C# 更新 Visual Studio 中的数据集结构以匹配新的 SQL 数据库结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9497689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Update DataSet structure in Visual Studio to match new SQL Database Structure
提问by MattyG
After making some changes to my SQL database structure (using scripts in SQL Server Management Studio), how can I update my DataSet.xsd file in Visual Studio to match the new structure? Must I do this manually?
I considered deleting the DataSet and importing a new one, but I'll lose all my custom Table Adapter queries.
对我的 SQL 数据库结构进行一些更改(使用 SQL Server Management Studio 中的脚本)后,如何更新 Visual Studio 中的 DataSet.xsd 文件以匹配新结构?我必须手动执行此操作吗?
我考虑删除数据集并导入一个新的数据集,但我将丢失所有自定义表适配器查询。
采纳答案by Steve
From the MSDN Forums:
来自MSDN 论坛:
If you right-click the TableAdapter in the Dataset Designer and click 'Configure' the TableAdapter Configuration Wizard opens where you can reconfigure the main query that defines the schema of your table. This should leave the additional TableAdapter queries (the additional methods) that were added after initial configuration.
Of course the additional methods will also need to be reconfigured if they reference a column that has been removed from the table on the database, or if any of the column definitions change (for example, if the data type is changed or modified). So if an aditional column was added to the table and it allows Null values the existing methods should still work - just depends on the scope of change to the schema of the table in the database.
如果您在数据集设计器中右键单击 TableAdapter 并单击“配置”,则会打开 TableAdapter 配置向导,您可以在其中重新配置定义表架构的主查询。这应该保留在初始配置后添加的附加 TableAdapter 查询(附加方法)。
当然,如果附加方法引用已从数据库表中删除的列,或者如果任何列定义发生更改(例如,如果更改或修改了数据类型),则也需要重新配置它们。因此,如果将附加列添加到表中并且它允许空值,则现有方法应该仍然有效 - 仅取决于数据库中表模式的更改范围。
回答by Jahuso
- Open the server explorer and browse through the Database to the table to be added
- Check the table is update
- Drag the table to your Dataset
- 打开服务器资源管理器,通过数据库浏览到要添加的表
- 检查表是否更新
- 将表拖到您的数据集

