namespace chengjiguanli
{
public partial class Banjixinxi_xiugai : Form
{
SqlConnection conn = null;
SqlCommand cmd = null;
public Banjixinxi_xiugai()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string sjk = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
conn = new SqlConnection(sjk);
if ((this.textBox2 .Text.Trim() == "") || (this.textBox3 .Text.Trim() == "") || this.textBox4 .Text.Trim() == "")
MessageBox.Show("请输入完整的课程信息","提示");
else
{
conn.Open();
string sql = "select * from gerenxinxi where 学号<>'" + this.textBox1.Text .ToString() + "' and 姓名='" + this.textBox2 .Text .ToString() + "'";
cmd = new SqlCommand(sql, conn);
if (null != cmd.ExecuteScalar())
MessageBox.Show("姓名发生重复", "提示");
else
{
string sql1 = "update gerenxinxi set 姓名='" + this.textBox2.Text.Trim() + "',性别='" + this.textBox3.Text.Trim() + "',班级='" + this.textBox4.Text.Trim() + "', 专业='" + this.textBox5.Text.Trim() + "',出生日期='" + this.textBox6.Text.Trim() + "',家庭住址='" + this.textBox7.Text.Trim() + "'" +
" where 学号='" + this.textBox1 .Text.Trim() + "'";
cmd = new SqlCommand(sql1, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("学生信息修改成功", "提示");
this.Close();
}
conn.Close();
} } private void button2_Click(object sender, EventArgs e)
{
this.Close(); }
}
}
修改完成后可以查询出来修改,关掉程序再打开程序依然可以查询到,但是过一段时间就查不到修改了。很奇怪。物理数据库一直没有变化。
{
public partial class Banjixinxi_xiugai : Form
{
SqlConnection conn = null;
SqlCommand cmd = null;
public Banjixinxi_xiugai()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string sjk = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\db.mdf;Integrated Security=True;User Instance=True";
conn = new SqlConnection(sjk);
if ((this.textBox2 .Text.Trim() == "") || (this.textBox3 .Text.Trim() == "") || this.textBox4 .Text.Trim() == "")
MessageBox.Show("请输入完整的课程信息","提示");
else
{
conn.Open();
string sql = "select * from gerenxinxi where 学号<>'" + this.textBox1.Text .ToString() + "' and 姓名='" + this.textBox2 .Text .ToString() + "'";
cmd = new SqlCommand(sql, conn);
if (null != cmd.ExecuteScalar())
MessageBox.Show("姓名发生重复", "提示");
else
{
string sql1 = "update gerenxinxi set 姓名='" + this.textBox2.Text.Trim() + "',性别='" + this.textBox3.Text.Trim() + "',班级='" + this.textBox4.Text.Trim() + "', 专业='" + this.textBox5.Text.Trim() + "',出生日期='" + this.textBox6.Text.Trim() + "',家庭住址='" + this.textBox7.Text.Trim() + "'" +
" where 学号='" + this.textBox1 .Text.Trim() + "'";
cmd = new SqlCommand(sql1, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("学生信息修改成功", "提示");
this.Close();
}
conn.Close();
} } private void button2_Click(object sender, EventArgs e)
{
this.Close(); }
}
}
修改完成后可以查询出来修改,关掉程序再打开程序依然可以查询到,但是过一段时间就查不到修改了。很奇怪。物理数据库一直没有变化。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货