Exemplo n.º 1
0
 public bool Insert(IOpstiDomenskiObjekat objekat)
 {
     try
     {
         connection.Open();
         transaction = connection.BeginTransaction();
         SqlCommand command = new SqlCommand();
         command.Connection  = connection;
         command.Transaction = transaction;
         command.CommandText = $"insert into {objekat.Table()} values ({objekat.Insert()})";
         if (command.ExecuteNonQuery() == 0)
         {
             throw new Exception();
         }
         transaction.Commit();
         return(true);
     }
     catch (Exception e)
     {
         transaction.Rollback();
         Console.WriteLine(e.Message);
         return(false);
     }
     finally
     {
         connection.Close();
     }
 }