gridview ashx实现数据更新_录入时检测数据是否存在的验证

实现:无输入时,提示需要录入;重复时,提示已经存在。

一、数据库知识准备

--查找重复记录,重复记录是根据单个字段(bqid)来判断  select * from banqi where bqid in  (select bqid from banqi group by bqid having COUNT(bqid)>1)​--统计指定bqid的记录数  select COUNT(1) from banqi where bqid='333222'

二、代码

1、表单

2、Jquery

        function checkbqid() {            var bqid = $("#txtBqid").val();            if (bqid == "") { alert("请输入5位数班期ID"); return; }            $.ajax({                type: 'get',                url: 'bqidcheck.ashx',                contentType: "application/json;charset=utf-8",                dataType: "text",                data: {bqid: bqid},                success: function (data) {                    $("#remind").html(""); $("#txtBqid").focus();                },                error: function () {                    $("#remind").html("");                }            });        }

3、ashx

string bqid = context.Request.QueryString["bqid"];bool result = new DAL.banqi().Exists(bqid);context.Response.ContentType = "text/plain";context.Response.Write(result);

4、DAL

       //检测bqid是否存在        public bool Exists(string bqid)        {            StringBuilder strSql = new StringBuilder();            strSql.Append("select  count(1) from banqi");            strSql.Append(" where bqid=@bqid");            SqlParameter[] parameters = {                    new SqlParameter("@bqid",SqlDbType.NVarChar,20)};            parameters[0].Value = bqid;            int res= new SqlHelper().ExecuteNonQuery(strSql.ToString(), parameters, CommandType.Text);            if (res > 0)            {                return true;            }            else            {                return false;            }        }
19be5ffe1ff26f203dab363598c9b059.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值