ASP.net串連mysql資料庫(使用MySql.Data.dll)

來源:互聯網
上載者:User

標籤:右擊   asp.net   object   技術分享   l資料庫   exe   資料   pen   串連數   

以前用ASP.net做web網站時用的都是sqlserver 資料庫,也沒有瞭解用mysql如何串連,遂今天試了下,多餘就不說了,直接上步驟了。

首先我採用的是MySql.Data.dll這種方式串連資料庫,我把放在百度雲上了,大家可以下載:http://pan.baidu.com/s/1o78bql0

mysql的安裝我就不多說了,傻瓜式安裝即可,這裡推薦一個視覺化檢視

可以方便看到資料庫裡的表:為了簡單測試我就把資料庫ll表裡放了一個欄位date

接下來,在ASP.net項目中右擊添加MySql.Data.dll的引用,如:

添加引用後,我們會在Bin下面看到這個引用,

 

到這一步配置就搞定了,接下來測試下:

在頁面中加入gridview空間,在cs中輸入:

protected void Page_Load(object sender, EventArgs e)    {        string conn = "Data Source=127.0.0.1;User ID=root;Password=root;DataBase=lp";        MySqlConnection con = new MySqlConnection(conn);        con.Open();        MySqlCommand cmd = new MySqlCommand("select * from ll", con);        MySqlDataReader dr = cmd.ExecuteReader();        GridView1.DataSource = dr;        GridView1.DataBind();        dr.Close();        con.Close();    }

最後效果:

 

ASP.net串連mysql資料庫(使用MySql.Data.dll)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.