13
Chapter 4 Connector/NET Tutorials
Table of Contents
4.1 Tutorial: An Introduction to Connector/NET Programming ............................................................. 13
4.1.1 The MySqlConnection Object ........................................................................................... 13
4.1.2 The MySqlCommand Object ............................................................................................. 14
4.1.3 Working with Decoupled Data .......................................................................................... 17
4.1.4 Working with Parameters ................................................................................................. 20
4.1.5 Working with Stored Procedures ....................................................................................... 21
4.2 Tutorial: Connector/NET ASP.NET Membership and Role Provider ............................................... 23
4.3 Tutorial: Connector/NET ASP.NET Profile Provider ...................................................................... 26
4.4 Tutorial: Web Parts Personalization Provider ............................................................................... 28
4.5 Tutorial: Simple Membership Web Provider ................................................................................. 33
4.6 Tutorial: Using an Entity Framework Entity as a Windows Forms Data Source ............................... 37
4.7 Tutorial: Data Binding in ASP.NET Using LINQ on Entities ........................................................... 45
4.8 Tutorial: Generating MySQL DDL from an Entity Framework Model ............................................... 48
4.9 Tutorial: Basic CRUD Operations with Connector/NET ................................................................. 49
4.10 Tutorial: Configuring SSL with Connector/NET ........................................................................... 52
4.10.1 Using PEM Certificates in Connector/NET ....................................................................... 53
4.10.2 Using PFX Certificates in Connector/NET ....................................................................... 54
4.11 Tutorial: Using MySqlScript ....................................................................................................... 55
The following MySQL Connector/NET tutorials illustrate how to develop MySQL programs using
technologies such as Visual Studio, C#, ASP.NET, and the .NET, .NET Core, and Mono frameworks. Work
through the first tutorial to verify that you have the right software components installed and configured, then
choose other tutorials to try depending on the features you intend to use in your applications.
4.1 Tutorial: An Introduction to Connector/NET Programming
This section provides a gentle introduction to programming with MySQL Connector/NET. The code
example is written in C#, and is designed to work on both Microsoft .NET Framework and Mono.
This tutorial is designed to get you up and running with Connector/NET as quickly as possible, it does not
go into detail on any particular topic. However, the following sections of this manual describe each of the
topics introduced in this tutorial in more detail. In this tutorial you are encouraged to type in and run the
code, modifying it as required for your setup.
This tutorial assumes you have MySQL and Connector/NET already installed. It also assumes that you
have installed the world database sample, which can be downloaded from the MySQL Documentation
page. You can also find details on how to install the database on the same page.
Note
Before compiling the code example, make sure that you have added References to
your project as required. The References required are System, System.Data and
MySql.Data.
4.1.1 The MySqlConnection Object
For your MySQL Connector/NET application to connect to a MySQL database, it must establish a
connection by using a MySqlConnection object.