public static void Insert(NewsArticlesLocationsNameData data) { // Create and execute the command string sql = "Insert Into " + TABLE + "(" + "Description," + "NewsArticlesLocationsID," + "NewsArticlesID," + "OrgLocationsID," ; sql = sql.Substring(0, sql.Length - 1) + ") values(" + "@Description," + "@NewsArticlesLocationsID," + "@NewsArticlesID," + "@OrgLocationsID," ; sql = sql.Substring(0, sql.Length - 1) + ")"; 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("@Description", SqlDbType.VarChar, 100, ParameterDirection.Input, false, 0, 0, "Description", DataRowVersion.Proposed, data.Description.DBValue)); cmd.Parameters.Add(new SqlParameter("@NewsArticlesLocationsID", SqlDbType.Int, 0, ParameterDirection.Input, false, 10, 0, "NewsArticlesLocationsID", DataRowVersion.Proposed, data.NewsArticlesLocationsID.DBValue)); 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 cmd.ExecuteNonQuery(); }
public static void Update(NewsArticlesLocationsNameData data) { // Create and execute the command NewsArticlesLocationsNameData oldData = Load(); string sql = "Update " + TABLE + " set "; if (!oldData.Description.Equals(data.Description)) { sql = sql + "Description=@Description,"; } if (!oldData.NewsArticlesLocationsID.Equals(data.NewsArticlesLocationsID)) { sql = sql + "NewsArticlesLocationsID=@NewsArticlesLocationsID,"; } if (!oldData.NewsArticlesID.Equals(data.NewsArticlesID)) { sql = sql + "NewsArticlesID=@NewsArticlesID,"; } if (!oldData.OrgLocationsID.Equals(data.OrgLocationsID)) { sql = sql + "OrgLocationsID=@OrgLocationsID,"; } WhereClause w = new WhereClause(); 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.Description.Equals(data.Description)) { cmd.Parameters.Add(new SqlParameter("@Description", SqlDbType.VarChar, 100, ParameterDirection.Input, false, 0, 0, "Description", DataRowVersion.Proposed, data.Description.DBValue)); } 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(); } }
public static NewsArticlesLocationsNameData Load() { WhereClause w = new WhereClause(); SqlDataReader dataReader = GetListReader(DatabaseEnum.INTRANET, TABLE, w, null, true); if (!dataReader.Read()) { dataReader.Close(); throw new FinderException("Load found no rows for NewsArticlesLocationsName."); } NewsArticlesLocationsNameData data = GetDataObjectFromReader(dataReader); dataReader.Close(); return(data); }
private static NewsArticlesLocationsNameData GetDataObjectFromReader(SqlDataReader dataReader) { NewsArticlesLocationsNameData data = new NewsArticlesLocationsNameData(); if (dataReader.IsDBNull(dataReader.GetOrdinal("Description"))) { data.Description = StringType.UNSET; } else { data.Description = StringType.Parse(dataReader.GetString(dataReader.GetOrdinal("Description"))); } if (dataReader.IsDBNull(dataReader.GetOrdinal("NewsArticlesLocationsID"))) { data.NewsArticlesLocationsID = IntegerType.UNSET; } else { data.NewsArticlesLocationsID = new IntegerType(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); }