/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.Ip model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Ip("); strSql.Append("Ihid,Inum,Iip)"); strSql.Append(" values ("); strSql.Append("@Ihid,@Inum,@Iip)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Ihid", SqlDbType.Int, 4), new SqlParameter("@Inum", SqlDbType.Int, 4), new SqlParameter("@Iip", SqlDbType.NVarChar, 50) }; parameters[0].Value = model.Ihid; parameters[1].Value = model.Inum; parameters[2].Value = model.Iip; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LearnSite.Model.Ip model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Ip set "); strSql.Append("Ihid=@Ihid,"); strSql.Append("Inum=@Inum,"); strSql.Append("Iip=@Iip"); strSql.Append(" where Iid=@Iid"); SqlParameter[] parameters = { new SqlParameter("@Ihid", SqlDbType.Int, 4), new SqlParameter("@Inum", SqlDbType.Int, 4), new SqlParameter("@Iip", SqlDbType.NVarChar, 50), new SqlParameter("@Iid", SqlDbType.Int, 4) }; parameters[0].Value = model.Ihid; parameters[1].Value = model.Inum; parameters[2].Value = model.Iip; parameters[3].Value = model.Iid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.Ip GetModel(int Iid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Iid,Ihid,Inum,Iip from Ip "); strSql.Append(" where Iid=@Iid"); SqlParameter[] parameters = { new SqlParameter("@Iid", SqlDbType.Int, 4) }; parameters[0].Value = Iid; LearnSite.Model.Ip model = new LearnSite.Model.Ip(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Iid"].ToString() != "") { model.Iid = int.Parse(ds.Tables[0].Rows[0]["Iid"].ToString()); } if (ds.Tables[0].Rows[0]["Ihid"].ToString() != "") { model.Ihid = int.Parse(ds.Tables[0].Rows[0]["Ihid"].ToString()); } if (ds.Tables[0].Rows[0]["Inum"].ToString() != "") { model.Inum = int.Parse(ds.Tables[0].Rows[0]["Inum"].ToString()); } model.Iip = ds.Tables[0].Rows[0]["Iip"].ToString(); return(model); } else { return(null); } }