/// <summary> /// 更新一条数据 /// </summary> public bool Update(CtlDBAccess.Model.BatchModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Batch set "); strSql.Append("createTime=@createTime,"); strSql.Append("remark=@remark"); strSql.Append(" where batchName=@batchName "); SqlParameter[] parameters = { new SqlParameter("@createTime", SqlDbType.DateTime), new SqlParameter("@remark", SqlDbType.NVarChar,255), new SqlParameter("@batchName", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.createTime; parameters[1].Value = model.remark; parameters[2].Value = model.batchName; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(CtlDBAccess.Model.BatchModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Batch("); strSql.Append("batchName,createTime,remark)"); strSql.Append(" values ("); strSql.Append("@batchName,@createTime,@remark)"); SqlParameter[] parameters = { new SqlParameter("@batchName", SqlDbType.NVarChar, 50), new SqlParameter("@createTime", SqlDbType.DateTime), new SqlParameter("@remark", SqlDbType.NVarChar, 255) }; parameters[0].Value = model.batchName; parameters[1].Value = model.createTime; parameters[2].Value = model.remark; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CtlDBAccess.Model.BatchModel DataRowToModel(DataRow row) { CtlDBAccess.Model.BatchModel model = new CtlDBAccess.Model.BatchModel(); if (row != null) { if (row["batchName"] != null) { model.batchName = row["batchName"].ToString(); } if (row["createTime"] != null && row["createTime"].ToString() != "") { model.createTime = DateTime.Parse(row["createTime"].ToString()); } if (row["remark"] != null) { model.remark = row["remark"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public CtlDBAccess.Model.BatchModel GetModel(string batchName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 batchName,createTime,remark from Batch "); strSql.Append(" where batchName=@batchName "); SqlParameter[] parameters = { new SqlParameter("@batchName", SqlDbType.NVarChar, 50) }; parameters[0].Value = batchName; CtlDBAccess.Model.BatchModel model = new CtlDBAccess.Model.BatchModel(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }