標籤:windows ring sql root art 將不 roo email source
1、要串連MySql資料庫必須首先下載MySql官方的串連.net的檔案,檔案為http://dev.mysql.com/downloads/connector/net/6.6.html#downloads ,下載平台選擇.Net&Mono,下載ZIP免安裝版。
連接器/網是一個完整的ADO。淨MySQL的驅動程式。
從6.7版本開始,連接器/淨將不再包括MySQL Visual Studio整合。
該功能現在可以在一個單獨的產品可用MySQL呼籲Visual Studio使用MySQL安裝Windows
(見http://dev.mysql.com/tech-resources/articles/mysql-installer-for-windows.html)。
注意:請不要下載 6.6以上版本的驅動。
2、解壓縮剛才下載的mysql-connector-net-6.6.6-noinstall.zip檔案,裡面有幾個版本選擇,在這裡我選V4,
選中這幾個檔案,然後添加到C#項目的引用中,然後就可以編寫程式進行資料庫的操作了。
3、資料庫作業碼 InsertMySql.cs
using System;using System.Collections;using System.Configuration;using MySql.Data;using MySql.Data.MySqlClient;using System.Data;namespace Sql//資料庫簡單測試{ class InsertSql1 { public static void Main(string[] args) { string constr="server=localhost;User Id=root;password=219229;Database=reg"; MySqlConnection mycon=new MySqlConnection(constr); mycon.Open(); MySqlCommand mycmd = new MySqlCommand("insert into buyer(name,password,email) values(‘小王‘,‘dikd3939‘,‘[email protected]‘)",mycon); if (mycmd.ExecuteNonQuery()>0) { Console.WriteLine("資料插入成功!"); } Console.ReadLine(); mycon.Close(); } }}
C#調用MySql