Ejemplo n.º 1
0
 private static void InsertQuoteIntoDatabase(Quote quote)
 {
     string connectionString =
         @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Dev\Refactoring\Refactoring\Database1.mdf;Integrated Security=True";
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         SqlCommand cmd = new SqlCommand("INSERT INTO Quotes (Title, Text) VALUES (@Title, @Quote)");
         cmd.CommandType = CommandType.Text;
         cmd.Connection = connection;
         cmd.Parameters.AddWithValue("@Title", quote.Title);
         cmd.Parameters.AddWithValue("@Quote", quote.Body);
         connection.Open();
         cmd.ExecuteNonQuery();
     }
 }
Ejemplo n.º 2
0
        private static Quote ParseLine(string line)
        {
            string[] values = line.Split(',');

            string title = values[0];
            Console.WriteLine("title: {0}", title);

            string body = values[1];
            Console.WriteLine("quote: {0}", body);

            Quote quote = new Quote
            {
                Title = title,
                Body = body
            };

            return quote;
        }