110,561
社区成员
发帖
与我相关
我的任务
分享
if (MessageBox.Show("是否修改该条记录", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
con.Open();
SqlCommand cmd = new SqlCommand();
string str = "update [test].[dbo].[测试部门表] set 部门='" + this.textBox1.Text + "'where 部门编号=" + this.label3.Text + "";
cmd.CommandText = str;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
showinf();
MessageBox.Show("修改成功");
}
private void showinf()
{
using (SqlConnection con = new SqlConnection("Data Source=PC-1210AFB;Initial Catalog=test;User ID=sa;Password=....."))
{
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("select * from 测试部门表", con);
da.Fill(dt);
this.dataGridView1.DataSource = dt.DefaultView;
}
}
if(MessageBox.Show("是否删除该条记录","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
{
con.Open();
SqlCommand cmd = new SqlCommand();
string str = "delete from [test].[dbo].[测试部门表] where 部门=' " + this.textBox1.Text + " '";
cmd.CommandText = str;
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
showinf();
MessageBox.Show("删除成功");
}