如果在这段代码里添加判断录入的ID是否和书库里的ID重复,如果重复就插入失败,否则成功
private void button1_Click(object sender, EventArgs e)
{
//if (Select count(*) from ZDML where ZDID='"+textBox3.Text.Trim()+"')
//{label11.Text="很抱歉!你新增的诊断ID在系统中已经存在,请检查后再新增!";}
//else
//{
try
{
SqlConnection thisConnection = new SqlConnection(SQL.connectDB);
thisConnection.Open();
SqlCommand cmd = new SqlCommand("insert into ZDML (ZDID,LB,Name,ICDFL,ICDLX,PYM,WBM,LCBX,XBXZ,BZ) values('" + this.textBox3.Text + "','" + this.comboBox3.Text + "','" + this.textBox1.Text + "','" + this.comboBox2.Text + "','" + this.comboBox1.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox2.Text + "','" + this.textBox8.Text + "','" + this.textBox7.Text + "')", thisConnection);
SqlDataReader myreader = cmd.ExecuteReader();
//this.Close();
thisConnection.Close();
MessageBox.Show("增加成功!", "提示");
ClearAll();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
//}
}