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