SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=G\SQLEXPRESS;Initial Catalog=jinghei;Integrated Security=True;Pooling=False";
con.Open(); string str = "select * from Table4 where Dname='" + textBox1.Text.Trim() + "'";
SqlCommand com = new SqlCommand(str, con);
if (com.ExecuteScalar() != null)
{
MessageBox.Show("部门名称重复,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
string stie = "insert into Table4 (Dname,Dleader,Re) values ('" + textBox1.Text.Trim() + "','" + textBox2.Text.Trim() + "','" + textBox3.Text.Trim() + "')";
SqlCommand comm = new SqlCommand(stie, con);
comm.ExecuteNonQuery();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
MessageBox.Show("添加部门成功!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
con.Close();
我在实现在文本框输入数据在和数据表对比是不是相同,不相同就插入数据表,请问里面的判断相同的语句正确吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货