C#連結MySQL

來源:互聯網
上載者:User

標籤:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using MySql.Data.MySqlClient;namespace MySQLtest{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void btnConnect_Click(object sender, EventArgs e)        {            string strcn = "Server=127.0.0.1;User ID=root;Password=mysql;Database=student;CharSet=gbk;";            MySqlConnection cn = new MySqlConnection(strcn);//執行個體化連結            cn.Open();//開啟串連            MySqlCommand cmd = cn.CreateCommand();            /************************************************            cmd.CommandText = "insert stu (sno,sname,sclass) values(‘20161‘,‘tt‘,‘class1‘)";//SQL插入資料            cmd.CommandText = "insert stu values(‘20162‘,‘ll‘,‘class3‘)";            cmd.CommandText = "delete from stu";//刪除資料            cmd.CommandText = "delete from stu where sname=‘ll‘";            cmd.CommandText = "update stu set sclass=‘class2‘ where sclass=‘class3‘";//修改資料            ************************************************/            cmd.CommandType = CommandType.Text;            int i = cmd.ExecuteNonQuery();            cn.Close();//關閉串連        }    }}

上課學的C#連結Sql Server 因為一直用的MySQL 自己把它改成了C#連結MySQL

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.