First you have to download MySQL, today MySQL comes with connectors, also for .NET. Then you have to add MySql.Data.dll reference, in my case MySql.Data.dll was in C:\Program Files (x86)\MySQL\Connector NET 6.8.3\Assemblies\v4.5
Then code behind looks something like:
public MainWindow()
{
InitializeComponent();
string MyConString =
"SERVER=myserver;" +
"DATABASE=myDb;" +
"UID=username;" +
"PASSWORD=pass;Convert Zero Datetime=True";
string sql = "select * from slam_categories";
var connection = new MySqlConnection(MyConString);
var cmdSel = new MySqlCommand(sql, connection);
var dt = new DataTable();
var da = new MySqlDataAdapter(cmdSel);
da.Fill(dt);
dataGrid1.DataContext = dt;
}
Only thing on which you have to take care is Convert Zero Datetime=True, without that you will receive error:
Unable to convert MySQL date/time value to System.DateTime
XAML looks like
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid x:Name="dataGrid1" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding}"/>
</Grid>
</Window>
In XAML note ItemsSource="{Binding}"