Exemplo n.º 1
0
        public void AddDB()
        {
            SqlConnection connection = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename ='C:\Users\Nikitka\source\repos\Book\Book\BookDB.mdf'; Integrated Security = True");

            try
            {
                // Открываем подключение
                connection.Open();
                Console.WriteLine("Подключение открыто");



                int    ID         = Id;
                int    IdNode     = this.IdNode;
                string Name       = this.Name;
                int    Size       = this.Size;
                int    Popular    = this.Popular;
                string typeSender = ts.ToString();


                string sql = string.Format("Insert Into Book" +
                                           "(Id, IdNode, Name, Size, Popular, typeSender) Values(@Id, @IdNode, @Name, @Size, @Popular, @typeSender)");

                using (SqlCommand cmd = new SqlCommand(sql, connection))
                {
                    // Добавить параметры
                    cmd.Parameters.AddWithValue("@Id", Id);
                    cmd.Parameters.AddWithValue("@IdNode", IdNode);
                    cmd.Parameters.AddWithValue("@Name", Name);
                    cmd.Parameters.AddWithValue("@Size", Size);
                    cmd.Parameters.AddWithValue("@Popular", Popular);
                    cmd.Parameters.AddWithValue("@typeSender", typeSender);

                    cmd.ExecuteNonQuery();
                }
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                // закрываем подключение
                connection.Close();
                Console.WriteLine("Подключение закрыто...");
            }
        }
Exemplo n.º 2
0
 public override string ToString()
 {
     return(string.Format($"{IdRack.ToString()}\t{TEv.ToString()}\t{TimeEvent.ToString()}\t{typeSender.ToString()}"));
 }