I wanna edit this code so that it doesn't write article titles more than once. It should write an Article Title and under it should be all its comments. Any suggestions? (I am new to SQL so please be nice). Also I would like to specify when printing the Content that it's the Comment's content because the table Articles also has a Content in my database. Thank you.
string connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename = C:\Users\kunde\Desktop\Kódy\RedakcniSystemDB\Database.mdf; Integrated Security = True";
//Console.WriteLine(connectionString);
using (SqlConnection connection= new SqlConnection(connectionString))
{
pripojeni.Open();
Console.WriteLine("Successfuly connected to database.");
using (SqlCommand command = new SqlCommand("SELECT [Articles].[Title], [Comments].[Content] FROM [Articles] JOIN [Comments] ON [Comments].[ArticleId] = [Articles].[Id]", connection))
{
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Console.WriteLine();
Console.WriteLine(reader["Title"]);
Console.WriteLine(reader["Content"]);
}
}
}
}
Console.ReadKey();