从数据集表创建数据库表 [英] Create DB table from dataset table

查看:136
本文介绍了从数据集表创建数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可能(在Vb.Net 2005中),无需手动解析数据集表属性,创建表并将其添加到数据库?

Is it possible (in Vb.Net 2005), without manually parsing the dataset table properties, to create the table and add it to the database?

我们的程序的旧版本在一些机器上,这显然有我们的旧数据库,我们正在寻找一种方法来检测是否有一个缺少表,然后根据数据集中的表的当前状态生成表。我们在每次发布新版本时重新编写表格(如果添加了新列),但我们希望尽可能避免此步骤。

We have old versions of our program on some machines, which obviously has our old database, and we are looking for a way to detect if there is a missing table and then generate the table based on the current status of the table in the dataset. We were re-scripting the table every time we released a new version (if new columns were added) but we would like to avoid this step if possible.

推荐答案

查看此MSDN论坛帖子:在ADO.net DataTable中创建SQL Server中的新表

See this MSDN Forum Post: Creating a new Table in SQL Server from ADO.net DataTable.

这里的海报似乎试图做与你一样的事情,并提供使用包含在DataTable中的模式生成一个Create Table语句的代码。

Here the poster seems to be trying to do the same thing as you, and provides code that generates a Create Table statement using the schema contained in a DataTable.

假设这应该正常工作,您可以接受该代码,并通过 SqlCommand.ExecuteNonQuery()以创建您的表。

Assuming this works as it should, you could then take that code, and submit it to the database through SqlCommand.ExecuteNonQuery() in order to create your table.

这篇关于从数据集表创建数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆