C#調用MySql

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.