/// <summary> /// 更新一条数据 /// </summary> public bool Update(BookShop.Model.Publishers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Publishers set "); #warning 系统发现缺少更新的字段,请手工确认如此更新是否正确! strSql.Append("Id=@Id,"); strSql.Append("Name=@Name"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@Name", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.Id; parameters[1].Value = model.Name; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(BookShop.Model.Publishers model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Publishers("); strSql.Append("Name)"); strSql.Append(" values ("); strSql.Append("@Name)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Name", SqlDbType.NVarChar, 200) }; parameters[0].Value = model.Name; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Publishers DataRowToModel(DataRow row) { BookShop.Model.Publishers model=new BookShop.Model.Publishers(); if (row != null) { if(row["Id"]!=null && row["Id"].ToString()!="") { model.Id=int.Parse(row["Id"].ToString()); } if(row["Name"]!=null) { model.Name=row["Name"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Publishers DataRowToModel(DataRow row) { BookShop.Model.Publishers model = new BookShop.Model.Publishers(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Publishers GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Name from Publishers "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; BookShop.Model.Publishers model = new BookShop.Model.Publishers(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public BookShop.Model.Publishers GetModel(int Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Id,Name from Publishers "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; BookShop.Model.Publishers model=new BookShop.Model.Publishers(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }