首先:找到mysql文件夹里面的这个文件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static string conStr = "server=127.0.0.1;user=root;password=1111; database=stu_db;"; MySqlConnection conn = new MySqlConnection(conStr); private void Form1_Load(object sender, EventArgs e) { conn.Open(); MessageBox.Show("连接完成~"); /* Update();*/ conn.Close(); } } }
上图,我们把id为1的数据给删除掉了
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static string conStr = "server=127.0.0.1;user=root;password=1111; database=stu_db;"; MySqlConnection conn = new MySqlConnection(conStr); private void Form1_Load_1(object sender, EventArgs e) { conn.Open(); MessageBox.Show("连接完成~"); MyUpdate(); conn.Close(); } void MyUpdate() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "DELETE FROM user WHERE id=1"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); /* textBox1.Text = result.ToString();*/ if (result != 0) { MessageBox.Show("完成"); } } } }using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static string conStr = "server=127.0.0.1;user=root;password=1111; database=stu_db;"; MySqlConnection conn = new MySqlConnection(conStr); private void Form1_Load_1(object sender, EventArgs e) { conn.Open(); MessageBox.Show("连接完成~"); /* MyDelete();*/ MyInsert(); conn.Close(); } //夜光:删除方法 void MyDelete() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "DELETE FROM user WHERE id=1"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); /* textBox1.Text = result.ToString();*/ if (result != 0) { MessageBox.Show("夜光:删除完成"); } } //夜光:更新方法 void MyInsert() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "insert into user(id,name,pwd) values(10,'aa','111')"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); /* textBox1.Text = result.ToString();*/ if (result != 0) { MessageBox.Show("夜光:新增完成"); } } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static string conStr = "server=127.0.0.1;user=root;password=1111; database=stu_db;"; MySqlConnection conn = new MySqlConnection(conStr); private void Form1_Load_1(object sender, EventArgs e) { conn.Open(); MessageBox.Show("连接完成~"); /*MyDelete();*/ /*MyInsert();*/ MyQuery(); conn.Close(); } //夜光:删除方法 void MyDelete() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "DELETE FROM user WHERE id=1"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); /* textBox1.Text = result.ToString();*/ if (result != 0) { MessageBox.Show("夜光:删除完成"); } } //夜光:更新方法 void MyInsert() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "insert into user(id,name,pwd) values(10,'aa','111')"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); /* textBox1.Text = result.ToString();*/ if (result != 0) { MessageBox.Show("夜光:新增完成"); } } //夜光:查找方法 void MyQuery() { /* string sql = "update students set 姓名='Genius Team' where 学号='001'";*/ /* string sql = "SELECT * FROM students";*/ string sql = "SELECT * FROM user where id=2"; MySqlCommand mys = new MySqlCommand(sql, conn); int result = mys.ExecuteNonQuery(); textBox1.Text = mys.ToString(); if (result != 0) { MessageBox.Show("夜光:查询完成"); } } } }