private static NewsArticlesLocationsData GetDataObjectFromReader(SqlDataReader dataReader) { NewsArticlesLocationsData data = new NewsArticlesLocationsData(); if (dataReader.IsDBNull(dataReader.GetOrdinal("NewsArticlesLocationsID"))) { data.NewsArticlesLocationsID = IdType.UNSET; } else { data.NewsArticlesLocationsID = new IdType (dataReader.GetInt32(dataReader.GetOrdinal("NewsArticlesLocationsID"))); } if (dataReader.IsDBNull(dataReader.GetOrdinal("NewsArticlesID"))) { data.NewsArticlesID = IntegerType.UNSET; } else { data.NewsArticlesID = new IntegerType (dataReader.GetInt32(dataReader.GetOrdinal("NewsArticlesID"))); } if (dataReader.IsDBNull(dataReader.GetOrdinal("OrgLocationsID"))) { data.OrgLocationsID = IntegerType.UNSET; } else { data.OrgLocationsID = new IntegerType (dataReader.GetInt32(dataReader.GetOrdinal("OrgLocationsID"))); } return data; }
public static IdType Insert(NewsArticlesLocationsData data) { // Create and execute the command string sql = "Insert Into " + TABLE + "(" + "NewsArticlesID," + "OrgLocationsID," ; sql = sql.Substring(0, sql.Length - 1) + ") values(" + "@NewsArticlesID," + "@OrgLocationsID," ; sql = sql.Substring(0, sql.Length - 1) + ");select Scope_Identity() Id"; SqlCommand cmd = GetSqlCommand(DatabaseEnum.INTRANET, sql, CommandType.Text, COMMAND_TIMEOUT); //Create the parameters and append them to the command object cmd.Parameters.Add(new SqlParameter("@NewsArticlesID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "NewsArticlesID", DataRowVersion.Proposed, data.NewsArticlesID.DBValue)); cmd.Parameters.Add(new SqlParameter("@OrgLocationsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "OrgLocationsID", DataRowVersion.Proposed, data.OrgLocationsID.DBValue)); // Execute the query SqlDataReader returnValue = cmd.ExecuteReader(); returnValue.Read(); int returnId = (int)(returnValue.GetDecimal(0)); returnValue.Close(); // Set the output paramter value(s) return new IdType (returnId); }
public static NewsArticlesLocationsData Load(IdType newsArticlesLocationsID) { WhereClause w = new WhereClause(); w.And("NewsArticlesLocationsID", newsArticlesLocationsID.DBValue); SqlDataReader dataReader = GetListReader(DatabaseEnum.INTRANET, TABLE, w, null, true); if (!dataReader.Read()) { dataReader.Close(); throw new FinderException("Load found no rows for NewsArticlesLocations."); } NewsArticlesLocationsData data = GetDataObjectFromReader(dataReader); dataReader.Close(); return data; }
public static void Update(NewsArticlesLocationsData data) { // Create and execute the command NewsArticlesLocationsData oldData = Load ( data.NewsArticlesLocationsID); string sql = "Update " + TABLE + " set "; if (!oldData.NewsArticlesID.Equals(data.NewsArticlesID)) { sql = sql + "NewsArticlesID=@NewsArticlesID,"; } if (!oldData.OrgLocationsID.Equals(data.OrgLocationsID)) { sql = sql + "OrgLocationsID=@OrgLocationsID,"; } WhereClause w = new WhereClause(); w.And("NewsArticlesLocationsID", data.NewsArticlesLocationsID.DBValue); sql = sql.Substring(0,sql.Length - 1) + w.FormatSql(); SqlCommand cmd = GetSqlCommand(DatabaseEnum.INTRANET, sql, CommandType.Text, COMMAND_TIMEOUT); //Create the parameters and append them to the command object if (!oldData.NewsArticlesLocationsID.Equals(data.NewsArticlesLocationsID)) { cmd.Parameters.Add(new SqlParameter("@NewsArticlesLocationsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "NewsArticlesLocationsID", DataRowVersion.Proposed, data.NewsArticlesLocationsID.DBValue)); } if (!oldData.NewsArticlesID.Equals(data.NewsArticlesID)) { cmd.Parameters.Add(new SqlParameter("@NewsArticlesID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "NewsArticlesID", DataRowVersion.Proposed, data.NewsArticlesID.DBValue)); } if (!oldData.OrgLocationsID.Equals(data.OrgLocationsID)) { cmd.Parameters.Add(new SqlParameter("@OrgLocationsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "OrgLocationsID", DataRowVersion.Proposed, data.OrgLocationsID.DBValue)); } // Execute the query if (cmd.Parameters.Count > 0) { cmd.ExecuteNonQuery(); } }