// NOT including image DATA, as that's not 'compulsory' data public void insertRow(ASComicAccess.xkcd.ComicMetadata metadata) { int num = int.Parse(metadata.num); string img = metadata.img; string safe_title = metadata.safe_title; string alt = metadata.alt; string transcript = metadata.transcript; string date = metadata.day + ":" + metadata.month + ":" + metadata.year; using (SqlCeConnection conn = new SqlCeConnection(@"Data Source = " + dbPath)) // DB connection { using (SqlCeCommand cmd = new SqlCeCommand(@"INSERT comics (num, img, safe_title, alt, transcript, date) VALUES (@num, @img, @safe_title, @alt, @transcript, @date)")) // SQL command { // Add C# data to the SQL query cmd.Parameters.AddWithValue(@"@num", num); //cmd.Parameters.Add(new SqlCeParameter("@num", num)); cmd.Parameters.AddWithValue(@"@img", img); cmd.Parameters.AddWithValue(@"@safe_title", safe_title); cmd.Parameters.AddWithValue(@"@alt", alt); cmd.Parameters.AddWithValue(@"@transcript", transcript); cmd.Parameters.AddWithValue(@"@date", date); conn.Open(); // Open DB connection cmd.Connection = conn; cmd.ExecuteNonQuery(); // Run query } } }
// Get comic by ID test private bool testComicByID(ASComicAccess.xkcd testClass, int ID) { ASComicAccess.xkcd.ComicMetadata metadata; try { metadata = testClass.getComic(ID); } catch { return false; // Test failed. } output = ("\n ID (string): " + (string)metadata.num + "\nComic Title (string): " + (string)metadata.safe_title + "\n"); // Generate output return true; }