public static List <JournalList> view(int LogID) { string SELECT = "SELECT J.JournalID, J.LogInID, J.Title, J.[Entry] FROM [User info] AS U INNER JOIN [Journal entry] AS J ON U.LogInID = J.LogInID WHERE J.LogInID = @logID"; SqlCommand command = new SqlCommand(SELECT, JournalWebsite); command.Parameters.AddWithValue("@logID", LogID); JournalWebsite.Open(); SqlDataReader reader = command.ExecuteReader(); List <JournalList> full = new List <JournalList>(); while (reader.Read()) { JournalList journal = new JournalList(); journal.JournalID = (int)reader["JournalId"]; journal.LogID = (int)reader["LogInID"]; journal.Title = reader["Title"].ToString(); journal.Entry = reader["Entry"].ToString(); full.Add(journal); } JournalWebsite.Close(); return(full); }
public static JournalList entry(JournalList newentry) { string INSERT = "INSERT INTO [Journal entry] ([LogInID], [Title], [Entry]) VALUES (@ID, @JournalTitle, @JournalEntry)"; SqlCommand command = new SqlCommand(INSERT, JournalWebsite); command.Parameters.AddWithValue("@ID", newentry.LogID); command.Parameters.AddWithValue("@JournalTitle", newentry.Title); command.Parameters.AddWithValue("@JournalEntry", newentry.Entry); JournalWebsite.Open(); command.ExecuteNonQuery(); JournalWebsite.Close(); if (newentry.Entry == "" || newentry.Entry.Length < 1) { return(null); } else { return(newentry); } }