球球救救孩子吧
就只能停止调试才能关掉
怎么办啊
我的代码:
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 宿舍管理
{
public partial class 删除 : Form
{
MySqlConnection SQLCon;
MySqlCommand SQLCmd;
string SNO = "null", SNAME = "null", SSEX = "null", SMAJOR = "null", SCLASS = "null", SDEPT = "null", RNO = "null", BNO = "null", DNO = "null";
public 删除()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetStr = "server=localhost;user=root;password=yuliu422623;database=sushe;";
SQLCon = new MySqlConnection(connetStr);
SQLCon.Open();
if (textBox1.Text.Trim() != "")
{
try
{
SNO = textBox1.Text;
string searchStr = ("delete from student where SNO=" + SNO );
SQLCmd = new MySqlCommand(searchStr, SQLCon);
SQLCmd.ExecuteNonQuery();
MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK);
button1_Click(sender, e);
if (MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK) == DialogResult.OK)
{
Application.Exit();
this .Close();
}
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
}
}
else
{
try
{
for (int i = 0; i < 100; i++)//遍历所有选中的行
{
if (dataGridView1.Rows[i].Selected == true)
{
string value = dataGridView1.Rows[i].Cells[0].Value.ToString();
int tmp = Convert.ToInt32(value);
string sql = ("delete from student where SNO=" + tmp);
SQLCmd = new MySqlCommand(sql, SQLCon);
SQLCmd.ExecuteNonQuery();
MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK);
button1_Click(sender, e);
break;
}
}
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK);
}
}
MySqlConnection conn = new MySqlConnection("server=localhost;database=sushe;uid=root;pwd=yuliu422623");
MySqlCommand cmd = new MySqlCommand("select * from student", conn);
MySqlDataAdapter sda = new MySqlDataAdapter("select * from student", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "student");
dataGridView1.DataSource = ds.Tables[0];
}
private void button2_Click(object sender, EventArgs e)
{
this.Visible = false;
Form3 nf = new Form3();
nf.ShowDialog();
}
}
}
因为本来也不是特别懂,好多代码都是网上找的。