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