打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用C#将数据插入数据库,判断是否重复
protected void submit_Click(object sender, EventArgs e)
{
string code;
code = Convert.ToString(this.TextBox1.Text);
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"'", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
code = regex.Replace(code, " ");
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=CodeRead;uid=sa;pwd= ");
conn.Open();
string sql = "select Count(1) from code where numble=('" + code + "')";
SqlCommand cmd1 = new SqlCommand(sql, conn);
int count = (int)cmd1.ExecuteScalar();
if (count > 1)
Response.Write("数据重复!");
else
{
SqlCommand cmd = new SqlCommand("insert into code(numble) values('" + code + "')", conn);
cmd.ExecuteNonQuery();
if (cmd.ExecuteNonQuery() > 0)
Response.Write(code + "数据导入成功!");
else
Response.Write("数据导入错误!");
conn.Close();
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c#实现文本框下拉框效果!(Winform)
VS连接SQL Server 2008,并实现登录和注册功能
ExecuteNonQuery对select无效
AJAX在线音乐网站(4)Part two 功能实现
C#数据库编程
Visual C#中动态操作SQL Server数据库
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服