To begin creating a new Windows Forms Project, you can either:
Click File from the main navigation menu, and then select New Project.
From the MySQL toolbar inside Visual Studio. To enable the toolbar, select View from the main navigation menu, and choose MySQL from the Toolbar menu.
From the MySQL toolbar, click the New Project button to open the Create new MySQL project wizard.
Step one -- Select the database connection for web authentication:
First, set up a connection to your MySQL Database.
The data source configuration step allows you to customize the connection and database for your application. The connection string can be selected from the dropdown list, or a new connection can be set up by clicking New Connection .
After the MySQL connection is set up and selected, the connection string is listed for review. While the wizard can generate a MySQL connection string that includes your credentials, this insecure practice is not recommended because the credentials would be shown as plain text in the web configuration file.
In addition to the data connection, you must also define the data access technology used to connect your database with the forms that the wizard will generate. You can choose between three options:
Typed Dataset: Generates a typed dataset
Entity Framework version 5.0: Database
First, based on
Entity Framework version 6.0: Database
First, based on
Step two -- Database objects selection:
Now, a list of tables from your selected database is listed. Select the tables used by your application.
Every table represents a Form in your application. In the grid, the Customize column contains buttons that trigger their own wizard that helps you select the layout for the generated form for the individual tables.
There are three types of views (layouts) that you can select from when customizing the forms:
Single column (default): each column of the table can be edited with an input textbox, with the following exceptions:
Datetime types are entered with DateTimePicker control.
Boolean types are entered with a checkbox control.
This follows the standard rule of Connector/NET and its
Entity Framework provider. When treated as booleans,
these columns (which are tinyint(1), bit, bool, or
boolean) have the default connection string setting
Foreign Keys, can optionally be rendered as Lookup ComboBox control.
A lookup combobox is a combobox (or drop down list) that displays a list of friendly values for the user, but internally they translate to numeric ID, which is more efficient for the database. For example, it is possible for the "sakila.customer" table to render a lookup Combobox for the "address_id" column using the more friendly "sakila.address.district" name (the referenced table from the FK that links table "customer" with "address"). So, when the user selects a new district and saves the changes, the address_id of the row for the new district is stored as the new foreign key value for that customer row.
DataGrid layout: The entire range of columns for the table is rendered inside a grid, as one grid row per row table, and one grid column per table column.
Master Detail Layout: Shows records of two tables linked through a foreign key constraint. The master records are displayed using an individual controls layout, and the detail records are displayed in a DataGrid layout.
By default, selected tables are configured using the Single Column layout.
For any type of generated model, it includes all of the tables for the required CRUD, including extra tables for master, and referenced tables in foreign keys.
Clicking Customize to customize the layout or view for a table. Only one type of view can be selected for one table.
Additionally, the wizard can add customized validations based on each Column data type. To add these validation procedures, check the Show all the advanced steps in the wizard option. This adds an additional validation step in the wizard.
The following Columns Validation step is used to configure the validation options.
By default, the generated CRUD already enforces data type validations (such as not accepting letters when the type is numeric, only accepting well formed floating point types, checking boolean types (through check boxes), accepting valid dates, and so on.). Additionally, this step permits you to configure extra validations, like setting Maximum/Minimum values, enforcing foreign key integrity when the 'HasLookup' option is checked for foreign key columns, and so on.
The information on column datatypes and required status is automatically deduced from the database, and is read-only.
The validations are implemented using the Windows Forms ErrorProvider control, and the Validating event for the distinct controls.
The column validation step can be repeated if the Master-Detail is chosen. In our example, the second validation screen will be for the columns of the Detail table.
The following are a series of screenshots (with explanations) that relate to the validation routines and options.
The toolbar appears in all of the layouts, and the buttons are defined as (from left to right):
Move to First record
Move to previous record
(Input box) enter number of record to navigate to it directly.
Move to next record
Move to last record
Add a new record
Delete current record
Commit all changes to the database (any editions, deletions or added new records changes won’t be persisted if changes are not committed).
This screenshot shows the Customer table in the sakila database.
The following is an example that demonstrates ErrorProvider complaining that the FirstName column is mandatory (cannot be empty).
Another example for the generated CRUD using a DataGrid layout that also shows the datetimepicker control displayed while editing a date type column.
Several of the buttons are disabled in the DataGrid layout. In this case, use the standard shortcuts of the Windows Forms DataGridView to manipulate records. For example:
Go to last row (it is blank) in the grid to insert a new record
Select the current row as a whole using the grey rows on the left, and click Delete to remove the record
You still need to commit the changes when using the Grid layout
This last example shows a Master-Detail relationship using the film and film_actor tables in the sakila database.
Notice that friendly columns names were chosen by the wizard for the lookup combo boxes that correspond to the foreign key's language (in film table), actor_id, and film_id (the last two for the film_actor table).