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