/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.Publisher 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(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Publisher 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; Model.Publisher model = new Model.Publisher(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.Publisher model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Publishers set "); 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; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }