SIGN UP MEMBER LOGIN:    
Accessing MySql Database using ADO.NET
In this article, I will show you how to access MySQL server database using ODBC data provider. There are two ways to access MySQL Server database using ODBC data providers. First, using ODBC data source name and second by passing connection string direct in the OdbcConnection object.

Using MySQL Database

As I’ve been saying, working with different data sources is only a matter of changing the connection string. You can access a MySQL database either using a DSN or using the  direct database name in the connection string. You can use a database name directly as shown in the following code: Dim connectionString as string = "Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;" Or you can use an ODBC DSN, as you can see from the following code that I’ve used TestDSN DSN to connect to the data source: Dim conn As New OdbcConnection("DSN=TestDSN") To test this code, create a Windows application and add a DataGrid control to the form and write code listed in Listing 11-2 on the form load. As you can see in Listing this code is similar to the code you saw earlier. It creates a connection, a data adapter, fills the dataset from the data adapter, and sets the dataset’s DefaultViewManager as the DataGrid control’s DataSource property. Listing 11-2. Accessing a MySQL database Private Sub Form1_Load(sender As Object, e As System.EventArgs) Dim connectionString As String = "Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;"' Dim conn As New OdbcConnection(connectionString) conn.Open() Dim da As New OdbcDataAdapter("SELECT CustomerID, ContactName, ContactTitle FROM Customers", conn) Dim ds As New DataSet("Cust") da.Fill(ds, "Customers") dataGrid1.DataSource = ds.DefaultViewManager conn.Close() End Sub 'Form1_Load Note: In this code, I have converted Northwind Access database to MySQL database. You make sure you replace your database name, table, user ID and password.  
About the Author
Mahesh Chand is a .NET consultant, author and the admin and founder of C# Corner. He has been working with .NET technology since pre beta releases.  Mahesh's background includes Master's in Computer Science and Applications and B.Sc. Mathematics. He is also a Microsoft Certified Professional.  Publication: Mahesh's publication includes the following titles -
Graphics Programming with GDI+
"This is the most comprehensive book about graphics programming using GDI+ so far. This book will be a very useful handbook for everyone who does graphics programming for Windows." --Min Liu, Software Design Engineer of GDI+, Microsoft CorporationGraphics Programming with GDI+ is the .NET developer's guide to writing graphics applications for Windows and the Web. Through the use of detailed examples it provides experienced programmers with a deep understanding of the entire GDI+ API defined in the .NET Framework class library.
 
Applied ADO.NET: Building Data-Driven Solutions
User level: Intermediate This book is written for intermediate to advanced developers who want to design database based Windows and Web solutions Applied ADO.NET: Building Data-Driven Solutions provides extensive coverage of ADO.NET technology including ADO.NET internals, namespaces, classes, and interfaces. Where most books cover only SQL and OLE DB data providers, Mahesh Chand and David Talbot cover SQL, OLE DB, ODBC data providers and the latest additions to ADO.NET: Oracle, MySQL, and XML .NET data providers. Chand and Talbot also cover internals of data binding and they provide detailed coverage on both Windows Forms and Web Forms data binding and data-bound controls. Since XML plays a major role in .NET development, the authors also provide a comprehensive look at XML namespaces and classes, and how to integrate both with ADO.NET.
The Complete Guide for Visual C# Programmers
User level: Intermediate This book covers major components that make up C# and the .NET environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer. The book starts by introducing the reader to the .NET environment and some basic C# program examples.  The book then goes in depth on how to navigate the Visual Studio environment and introduces the reader to the C# language From here the book dives into the .NET framework and how to take advantage of its capabilities using C#.  Some of the topics covered in great detail include ADO.NET database programming,  ASP.NET and Web Services, COM interoperability programming,  security in .NET,  mobile phone programming,  GDI+ graphic programming,  multithreading, Windows Services,  XML and SOAP in .NET, and much more. Chapters in the book contain programming examples, reference tables, and step-by-step tutorials to guide you through one of Microsoft’s greatest achievements in programming environments.
A Programmer's Guide to ADO .NET in C#
User level: Beginner This book is written for beginners who want to write database applications using ADO.NET and C#.  This is the book on ADO.NET. ADO.NET is the latest database technology from Microsoft and represents the most powerful way to manipulate a database to date. A Programmer's Guide to ADO.NET in C# begins by taking readers through an overview of C# and then delves into ADO.NET. Author Mahesh Chand provides details on each of the major data providers of the .NET platform, such as OleDb, Sql, and ODBC, which enable developers to read and write data to the targeted databases. This book also serves as a good reference for finding detailed methods and properties for these data provider classes.