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

<p>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.</p>

[{'answer_id': 16840, 'author': 'Yaakov Ellis', 'author_id': 51, 'author_profile': 'https://Stackoverflow.com/users/51', 'pm_score': 3, 'selected': False, 'text': '<p>See this MSDN Forum Post: <a href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/4929a0a8-0137-45f6-86e8-d11e220048c3/" rel="nofollow noreferrer">Creating a new Table in SQL Server from ADO.net DataTable</a>. </p>\n\n<p>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. </p>\n\n<p>Assuming this works as it should, you could then take that code, and submit it to the database through <code>SqlCommand.ExecuteNonQuery()</code> in order to create your table.</p>\n'}, {'answer_id': 13625295, 'author': 'Prahalad Gaggar', 'author_id': 1841054, 'author_profile': 'https://Stackoverflow.com/users/1841054', 'pm_score': 2, 'selected': False, 'text': '<p>Here is the code:  </p>\n\n\n\n<pre class="lang-cs prettyprint-override"><code>SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa123;database=Example1");\ncon.Open();\nstring sql = "Create Table abcd (";\n\nforeach (DataColumn column in dt.Columns)\n{\n    sql += "[" + column.ColumnName + "] " + "nvarchar(50)" + ",";\n}\n\nsql = sql.TrimEnd(new char[] { \',\' }) + ")";\nSqlCommand cmd = new SqlCommand(sql, con);\nSqlDataAdapter da = new SqlDataAdapter(cmd);\ncmd.ExecuteNonQuery();\n\nusing (var adapter = new SqlDataAdapter("SELECT * FROM abcd", con)) \nusing(var builder = new SqlCommandBuilder(adapter))\n{\n    adapter.InsertCommand = builder.GetInsertCommand();\n    adapter.Update(dt);\n}\ncon.Close();\n</code></pre>\n\n<p>I hope you got the problem solved.<br>\nHere <code>dt</code> is the name of the DataTable.<br>\nAlternatively you can replace:  </p>\n\n<pre class="lang-cs prettyprint-override"><code>adapter.update(dt);\n</code></pre>\n\n<p>with</p>\n\n<pre class="lang-cs prettyprint-override"><code>//if you have a DataSet\nadapter.Update(ds.Tables[0]); \n</code></pre>\n'}]
['https://Stackoverflow.com/questions/16443', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1936/']