/// <summary> /// 更新一条数据 /// </summary> public bool Update(XCWeiXin.Model.wx_xt_user model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update wx_xt_user set "); strSql.Append("bId=@bId,"); strSql.Append("openid=@openid,"); strSql.Append("uName=@uName,"); strSql.Append("phone=@phone,"); strSql.Append("pNum=@pNum,"); strSql.Append("createDate=@createDate"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@bId", SqlDbType.Int, 4), new SqlParameter("@openid", SqlDbType.VarChar, 200), new SqlParameter("@uName", SqlDbType.VarChar, 100), new SqlParameter("@phone", SqlDbType.VarChar, 100), new SqlParameter("@pNum", SqlDbType.Int, 4), new SqlParameter("@createDate", SqlDbType.DateTime), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.bId; parameters[1].Value = model.openid; parameters[2].Value = model.uName; parameters[3].Value = model.phone; parameters[4].Value = model.pNum; parameters[5].Value = model.createDate; parameters[6].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public XCWeiXin.Model.wx_xt_user DataRowToModel(DataRow row) { XCWeiXin.Model.wx_xt_user model = new XCWeiXin.Model.wx_xt_user(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["bId"] != null && row["bId"].ToString() != "") { model.bId = int.Parse(row["bId"].ToString()); } if (row["openid"] != null) { model.openid = row["openid"].ToString(); } if (row["uName"] != null) { model.uName = row["uName"].ToString(); } if (row["phone"] != null) { model.phone = row["phone"].ToString(); } if (row["pNum"] != null && row["pNum"].ToString() != "") { model.pNum = int.Parse(row["pNum"].ToString()); } if (row["createDate"] != null && row["createDate"].ToString() != "") { model.createDate = DateTime.Parse(row["createDate"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(XCWeiXin.Model.wx_xt_user model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into wx_xt_user("); strSql.Append("bId,openid,uName,phone,pNum,createDate)"); strSql.Append(" values ("); strSql.Append("@bId,@openid,@uName,@phone,@pNum,@createDate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@bId", SqlDbType.Int, 4), new SqlParameter("@openid", SqlDbType.VarChar, 200), new SqlParameter("@uName", SqlDbType.VarChar, 100), new SqlParameter("@phone", SqlDbType.VarChar, 100), new SqlParameter("@pNum", SqlDbType.Int, 4), new SqlParameter("@createDate", SqlDbType.DateTime) }; parameters[0].Value = model.bId; parameters[1].Value = model.openid; parameters[2].Value = model.uName; parameters[3].Value = model.phone; parameters[4].Value = model.pNum; parameters[5].Value = model.createDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public XCWeiXin.Model.wx_xt_user GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,bId,openid,uName,phone,pNum,createDate from wx_xt_user "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; XCWeiXin.Model.wx_xt_user model = new XCWeiXin.Model.wx_xt_user(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }