求解释,代码很简单,但是我想不明白,望明白的认识指点下
程序代码:
<%@ WebHandler Language="C#" Class="deldata" %> using System; using System.Web; using System.Data; using System.Data.SqlClient; using System.Text; using System.Collections.Generic; public class deldata : IHttpHandler { public void ProcessRequest(HttpContext context) { Model model = new Model(); model.FName = context.Request.Form["FName"]; model.FCategoryID = IsNull(context.Request.Form["Fcate"]) ? (int?)Convert.ToInt32(context.Request.Form["Fcate"]) : null; model.FAuthor = context.Request.Form["Fauthor"]; model.IsDel = IsNull(context.Request.Form["Fcate"]) ? (bool?)Convert.ToBoolean(context.Request.Form["IdDel"]) : null; //context.Request.Form["IdDel"]; model.FYearPublished = IsNull(context.Request.Form["Fyear"]) ? (int?)Convert.ToInt32(context.Request.Form["Fyear"]) : null;//(int?) Convert.ToInt32(context.Request.Form["Fyear"]); //这里不理解,求解释 int rel = DelExecuteNonQuery(model, context); if (rel <= 0) { context.Response.Write("alert(\"删除失败\");"); } else { context.Response.Redirect("SelecteData.ashx"); } } public bool IsNull(object value) { if (value.ToString().Trim().Length == 0) { return false; } else { return true; } } public bool IsReusable { get { return false; } } public int DelExecuteNonQuery(Model model, HttpContext context) { List<SqlParameter> sqlParameterList = new List<SqlParameter>(); List<string> sqlList = new List<string>(); string sqlStr = "delete from T_Book"; if (model.FName.ToString().Trim().Length > 0) { sqlList.Add("FName like @FName"); sqlParameterList.Add(new SqlParameter("@FName", "%" + model.FName + "%")); } if (model.FCategoryID != null) { sqlList.Add("FCategoryID like @FCategoryID"); sqlParameterList.Add(new SqlParameter("@FCategoryID", "%" + model.FCategoryID + "%")); } if (model.FYearPublished != null) { sqlList.Add("FYearPublished like @FYearPublished"); sqlParameterList.Add(new SqlParameter("@FYearPublished", "%" + model.FYearPublished + "%")); } if (model.IsDel != null) { sqlList.Add("IsDel like @IsDel"); sqlParameterList.Add(new SqlParameter("@IsDel", "%" + model.IsDel + "%")); } if (model.FAuthor != string.Empty) { sqlList.Add("FAuthor like @FAuthor"); sqlParameterList.Add(new SqlParameter("@FAuthor", "%" + model.FAuthor + "%")); } if (sqlList.Count > 0) { string sqlTxt = string.Join(" and ", sqlList.ToArray()); sqlStr = sqlStr + " where " + sqlTxt; } else { context.Response.Write("alert(\" 你会把所有数据都删除掉的!!!\");"); return 0; } SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=Books;User ID=sa;Password=123"); con.Open(); SqlCommand com = new SqlCommand(); com.Connection = con; = sqlStr; com.Parameters.AddRange(sqlParameterList.ToArray()); int rel = com.ExecuteNonQuery(); return rel; } } 这算个模糊查询删除记录的一个小程序吧,HTML代码就不写了,这个是一般处理程序,问题就是我明明已经把要删除的记录删除了,并且上述做标记处代码中的rel变量是大于0的,但是调试过程中不知道什么原因,(我在if判断出设了断点),走到if判断处,按F11,语句往下执行,但是再按F11 又回到if判断处了,并且rel变量为0,求解释。期待中。。。。。。
[ 本帖最后由 lxb932979339 于 2013-5-30 21:33 编辑 ]