日期:2014-05-17 浏览次数:20734 次
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=table;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand(string.Format("select Count(*) form table where 编号= '{0}'", textBox1.Text), con);
if ((int)cmd.ExecuteScalar() > 0)
{
MessageBox.Show("数据已经存在", "提示");
}
else
{
string sql = "insert into table(编号,名字,部门,工作完成度,.....) values('" + textBox1.Text +"','"+textBox2.Text+"','"+textBox2.Text+"','"+RadioButton1.text+"','"+......."')"; cmd.CommandText = sql;
cmd.ExecuteNonQuery();
MessageBox.Show("成功添加");
}