Sei sulla pagina 1di 5

7/27/2014 How to Connect to MySQL Using C# - CodeProject

http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp 1/5
10,757,811 members (74,505 online)


Sign in
home quick answers discussions features community help Search f or articles, questions, tips
Articles Database Database MySQL

Tip
Browse Code
Stats
Revisions (3)
Alternatives
Comments (12)
About Article
Type Tip/Trick
Licence CPOL
First Posted 17 Jul 2012
Views 141,290
Bookmarked 32 times

Related Articles
Migrate MySQL to Microsoft
SQL Server
Connect C# to MySQL
C# ASP.NET MySQL Connection
Tutorial with MySQL Connector

Rate this: Ravindra T C, 17 Jul 2012
How to Connect to MySQL Using C#
How to connect to a MySQL database using the MySQL Connector for .NET.
Introduction
This article shows you how to connect to a MySQL database using the MySQL Connector for .NET. I will
also show you how you can update MySQL database records using C#.
Prerequisites
Install Visual Studio 2008 or Visual Studio 2010
Install MySQL database on your local machine
MySQL database admin tool that allows you to create a database and run SQL statements. I am
using phpMyAdmin which is a web interface.
Download and install MySQL Connector.
Getting Started
Run the XAMPP application and it will automatically install Apache server, MySQL database, and FileZilla.
After installing check whether these services are running or not. The following XAMPP control panel shows
which of those services are currently running.
Now the following steps will show how to connect to a MySQL database using C#.
4.86 (13 votes)
C# Dev Beginner
MySQL
articles
7/27/2014 How to Connect to MySQL Using C# - CodeProject
http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp 2/5
VB.NET to MySQL Database
Connection
MySqlBackup.NET - MySQL
Backup Solution for C#, VB.NET,
ASP.NET
Connecting to MySQL from
Visual C#
Connecting to MySQL Database
using C# and .NET
Connecting to MySQL
databases using VB.NET
Using MySQL from C# and
Mono.NET
Accessing: MySQL Database
using MySQL C API
Using MySQL with Entity
Framework
ADO Connection Strings
How to fix Timeout expired. The
timeout period elapsed prior to
completion of the operation or
the server is not responding
DALC4NET: A Generic Data
Access Layer for .NET
An ASP.NET Application Using a
MySQL Database
MySQL DB backup using
powershell script
Upload images into a MySQL
database using VC++
MFC and MySQL
Message Manager
MySQL Schema in C#
Related Research
Data Modeling for Effective
Data Warehousing and Business
Intelligence
IDC: The Intelligent Integrated
Enterprise
IDC: How Red Hat's JBoss
Enterprise Application Platform
is Extending Business Value
Step 1
Open MySQL Admin page and create a new database.
Step 2
After creating the new database, create a new table.
Step 3
After creating the new table, open Visual Studio and click on New Project and name the project. It will
open the new project, then click on Solution Explorer (F4), right click on Reference to add a new reference
into the project. Reference those two .dll files to the project (MySql.dll (Win apps), MySql.web.dll (Web
apps)).
Step 4
Add namespace to the project.
Step 5
Create a MySQL connection string.
Step 6
7/27/2014 How to Connect to MySQL Using C# - CodeProject
http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp 3/5
Toad Oracle: Tips to Simplify
Database Administration and
Development
The following code will insert the data into MySQL table.
Step 7
The following function will load the data from the table and bind it into a GridView.
Step 8
The final result is shown on the window form:
7/27/2014 How to Connect to MySQL Using C# - CodeProject
http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp 4/5
Ravindra T C
Software Developer L&T IES Mysore
India
I'm a software developer. I spent most of the time in learning new technologies. I've a keen
interest in client-side technologies especially JavaScript and Jquery it is the most beautiful
language ever seen.
I like sharing my knowledge and written some non-popular articles. I believe in quality and
standards but blames myself for lagging them.
I believe in small things and they makes me happy!

License
This article, along with any associated source code and files, is licensed under The Code Project Open
License (CPOL)
About the Author
Article Top
Comments and Discussions
You must Sign In to use this message board.
7/27/2014 How to Connect to MySQL Using C# - CodeProject
http://www.codeproject.com/Tips/423233/How-to-Connect-to-MySQL-Using-Csharp 5/5
Permalink | Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 17 Jul 2012
Article Copyright 2012 by Ravindra T C
Everything else Copyright CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid
Search this forum Go
Profile popups Spacing Relaxed Noise Medium Layout Normal Per page 25 Update
First Prev Next
sam.hill
13-Apr-14 16:38
msdevtech
29-Dec-13 8:56
Member 10401813
23-Nov-13 6:36
Dan Kudela
12-Mar-13 1:08
Dave Crump
27-Oct-12 0:36
Rudolf Grauberger
18-Sep-12 12:35
figgikim1
17-Sep-12 3:52
Rudolf Grauberger
15-Aug-12 8:05
PramodBNair
19-Jul-12 11:22
Ravindra T C
19-Jul-12 15:59
Ravindra T C
23-Jul-12 21:10
Frderic Cordier
17-Jul-12 20:04
Last Visit: 31-Dec-99 18:00 Last Update: 26-Jul-14 13:44 Refresh 1
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
My vote of 2
[My vote of 1] No sample project
thanks it was really helpful for me...!!!
Excellent!
My vote of 5
My vote of 3
My vote of 5
Use the using directive... [modified]
Could not load file or assembly 'MySql.Data.CF'
or one of its dependencies. The given assembly
name or codebase was invalid. (Exception from
HRESULT: 0x80131047)
Re: Could not load file or assembly 'MySql.Data.CF'
or one of its dependencies. The given assembly
name or codebase was invalid. (Exception from
HRESULT: 0x80131047)
Re: Could not load file or assembly 'MySql.Data.CF'
or one of its dependencies. The given assembly
name or codebase was invalid. (Exception from
HRESULT: 0x80131047)
What would be great also...

Potrebbero piacerti anche