/// <summary> /// 更新一条数据 /// </summary> public bool Update(Material.Model.level3 model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update level3 set "); strSql.Append("name=@name,"); strSql.Append("level2_id=@level2_id,"); strSql.Append("id3=@id3,"); strSql.Append("level1_id=@level1_id"); strSql.Append(" where "); SQLiteParameter[] parameters = { new SQLiteParameter("@name", DbType.char, 2147483647), new SQLiteParameter("@level2_id", DbType.Int32, 8), new SQLiteParameter("@id3", DbType.Int32, 8), new SQLiteParameter("@level1_id", DbType.Int32, 8) }; parameters[0].Value = model.name; parameters[1].Value = model.level2_id; parameters[2].Value = model.id3; parameters[3].Value = model.level1_id; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Material.Model.level3 model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into level3("); strSql.Append("name,level2_id,id3,level1_id)"); strSql.Append(" values ("); strSql.Append("@name,@level2_id,@id3,@level1_id)"); SQLiteParameter[] parameters = { new SQLiteParameter("@name", DbType.char, 2147483647), new SQLiteParameter("@level2_id", DbType.Int32, 8), new SQLiteParameter("@id3", DbType.Int32, 8), new SQLiteParameter("@level1_id", DbType.Int32, 8) }; parameters[0].Value = model.name; parameters[1].Value = model.level2_id; parameters[2].Value = model.id3; parameters[3].Value = model.level1_id; int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Material.Model.level3 GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select name,level2_id,id3,level1_id from level3 "); strSql.Append(" where "); SQLiteParameter[] parameters = { }; Material.Model.level3 model = new Material.Model.level3(); DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Material.Model.level3 DataRowToModel(DataRow row) { Material.Model.level3 model = new Material.Model.level3(); if (row != null) { if (row["name"] != null) { model.name = row["name"].ToString(); } if (row["level2_id"] != null && row["level2_id"].ToString() != "") { model.level2_id = int.Parse(row["level2_id"].ToString()); } if (row["id3"] != null && row["id3"].ToString() != "") { model.id3 = int.Parse(row["id3"].ToString()); } if (row["level1_id"] != null && row["level1_id"].ToString() != "") { model.level1_id = int.Parse(row["level1_id"].ToString()); } } return(model); }