user748261
user748261

Reputation: 151

DataSet - easy way to create new table?

I use Visual Studio 2010 with C# to write a database application. Until now, I used the guided dialog to add a DataSet to my current project. In the project explorer tree on the right side, a node "mydatabase.xsd" is created.

On the left side, I have the server explorer. From there, I can drag existing tables onto the DataSet-designer to create the references (to my understanding, VS auto-generates code in the background). The references (or TableAdapters etc. respectively) can be used in the source code, in the form of mydatabase.mytable

This is very convenient as I don't have to deal with the details of the connection settings, and it keeps SQL code out of my eyesight.

If, however, I want to create a new table in the existing database, VS does not seem to offer any assistance. I looked at the MSDN-specification. They tell you how to create the table object and the column definitions and how to link it to the DataSet, but not how to actually save it into the database. In all the examples I found on Google, you'd have to explicitly, manually, define a ConnectionString, SQL commands or similar. With all the VS GUI advancements, this seems rather convoluted to me. Is there an easy way to accomplish it?

Upvotes: 0

Views: 518

Answers (1)

rtalbot
rtalbot

Reputation: 1645

Open Server Explorer, click Add Data Connection and supply connection information to your database, click OK. Right Click on Tables folder and click Add Table. Add Fields, etc to your new datatable.

Upvotes: 2

Related Questions