C# 连接 MySQL 并进行数据库操作(入门篇) 已翻译 100%

曾沙 投递于 2012/11/27 16:47 (共 2 段, 翻译完成于 11-27)
阅读 30090
收藏 4
1
加载中

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.

已有 1 人翻译此段
我来翻译
Now the following steps will show how to connect to a MySQL database using C#.

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

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:

已有 1 人翻译此段
我来翻译
本文中的所有译文仅用于学习和交流目的,转载请务必注明文章译者、出处、和本文链接。
我们的翻译工作遵照 CC 协议,如果我们的工作有侵犯到您的权益,请及时联系我们。
加载中

评论(3)

crossmix
crossmix
步骤 一,步骤二
i
im0khu
用的是图片,比较麻烦。还得挨个自己敲命令。
另外文中最后的是Close(), 不是 Clone() 。初学者注意了。
龚晓龙
龚晓龙
不错不错,很受用
返回顶部
顶部