Auto-generate VB.NET forms using SQL Server 2008
I want to automatically generate VB.NET forms using tables from a SQL Server database (one form / database table). It is perhaps possible with writing custom custom code for it, but if there is already some feature that does the job that would be great (database has 40+ tables, manually doing this is a tedious task).
Any answers, help, links, tips is greatly appreciated.
One Solution collect form web for “Auto-generate VB.NET forms using SQL Server 2008”
It takes just a minute to fix, all functionality allready exists in Visual Studio.
Fire up Visual Studio, click on Add new datasource… to start the Data Source Configuration Wizard:
Select Database and follow the wizard:
When connected to the database, select the tables you are interrested in and press the Finnish button:
Now, this will create a strongly named dataset in your solution, if you double click the xsd file you’ll see the tables you selected in the schema editor, but leave that for now:
Now, select “Show Data Sources” from the data-menu and you will see all tables you selected in the wizard. To the left of each field its an icon that tells what type of control that field will be represented by on the resulting form:
Now you can deside how the data will be presented on the form, as a datagridview or in detail mode, just use the dropdown on the table name (only when in form-design-mode).
If you have selected details-mode on the table, then you can change what control the field will be represented by (must be in form-design-mode, not code-mode):
Then just drag the table from the data source view to an empty form and it will magically create controls to edit/add/delete and move around the data.
This is the result if DataGridView-mode was selected:
And if Details was selected on the table:
In code behind it also magically add some code to load the data to the adapter when the form loads and some save/validating code:
Private Sub AccountBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AccountBindingNavigatorSaveItem.Click Me.Validate() Me.AccountBindingSource.EndEdit() Me.AccountTableAdapter.Update(Me.MyDBDataSet.Account) End Sub Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'TODO: This line of code loads data into the 'MyDBDataSet.Account' table. You can move, or remove it, as needed. Me.AccountTableAdapter.Fill(Me.MyDBDataSet.Account) End Sub