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