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 data= '{0}'", textBox.Text), con);
if ((int)cmd.ExecuteScalar() > 0)
{
MessageBox.Show("数据已经存在", "提示");
}
else
{
string sql = "insert into table(data) values('" + textBox.Text + "')";
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
MessageBox.Show("成功添加");
}
数据入库代码
最新推荐文章于 2023-08-16 21:42:42 发布