Tratamento de erros

Delphi

09/08/2005

Ae pessoal, preciso saber se esta seria a melhor forma de tratar algum tipo de erro na minha programação, esse código tem a finalidade de exibir noticias em uma página web, porém quero saber se o try está da forma correta. se alguem tiver alguma sugestao pode mandar por favor...


procedure TWFindex.Page_Load(sender: System.Object; e: System.EventArgs); 
begin 
  MostrarDestaques(); 
  MostrarFoto(); 
  MostrarTodasNot(); 
  // TODO: Put user code to initialize the page here 
end; 

procedure TWFindex.MostrarDestaques; 
Var 
  ReaderMostrarDestaques : OdbcDataReader; 
  CommandMostrarDestaques: OdbcCommand; 
  sMostrarDestaques : System.Text.StringBuilder; 
begin 
  sMostrarDestaques := System.Text.StringBuilder.Create(); 
  sMostrarDestaques.Append(´SELECT noticia.noticia_id, noticia.noticia_titulo, ´ + 
    ´noticia.noticia_resumo, destaque_noticia.destaque_local FROM noticia, destaque_noticia ´ + 
    ´WHERE noticia.noticia_id = destaque_noticia.noticia_id AND destaque_pagina = "index.aspx"´); 
  CommandMostrarDestaques := OdbcCommand.Create(sMostrarDestaques.ToString(), Connection); 
  try 
    Connection.Open(); 
    ReaderMostrarDestaques := CommandMostrarDestaques.ExecuteReader(); 
    While ReaderMostrarDestaques.Read() do begin 
          if ReaderMostrarDestaques.Item[´destaque_local´].ToString = ´Notícia 1´ then begin 
            noticiadestaqueid := ReaderMostrarDestaques.Item[´noticia_id´].ToString; 
            noticia1t.Text := ReaderMostrarDestaques.Item[´noticia_titulo´].ToString; 
            noticia1t.NavigateUrl := ´detnoticia.aspx?id=´ + noticiadestaqueid; 
            noticia1txt.Text := ReaderMostrarDestaques.Item[´noticia_resumo´].ToString; 
          end 
          else if ReaderMostrarDestaques.Item[´destaque_local´].ToString = ´Notícia 2´ then begin 
            noticia2t.Text := ReaderMostrarDestaques.Item[´noticia_titulo´].ToString; 
            noticia2t.NavigateUrl := ´detnoticia.aspx?id=´ + ReaderMostrarDestaques.Item[´noticia_id´].ToString; 
            noticia2txt.Text := ReaderMostrarDestaques.Item[´noticia_resumo´].ToString; 
          end 
          else if ReaderMostrarDestaques.Item[´destaque_local´].ToString = ´Notícia 3´ then begin 
            noticia3t.Text := ReaderMostrarDestaques.Item[´noticia_titulo´].ToString; 
            noticia3t.NavigateUrl := ´detnoticia.aspx?id=´ + ReaderMostrarDestaques.Item[´noticia_id´].ToString; 
            noticia3txt.Text := ReaderMostrarDestaques.Item[´noticia_resumo´].ToString; 
          end 
          else if ReaderMostrarDestaques.Item[´destaque_local´].ToString = ´Notícia 4´ then begin 
            noticia4t.Text := ReaderMostrarDestaques.Item[´noticia_titulo´].ToString; 
            noticia4t.NavigateUrl := ´detnoticia.aspx?id=´ + ReaderMostrarDestaques.Item[´noticia_id´].ToString; 
            noticia4txt.Text := ReaderMostrarDestaques.Item[´noticia_resumo´].ToString; 
          end 
    end; 
    ReaderMostrarDestaques.Close(); 
    Connection.Close(); 
  except 
    if Connection.State = ConnectionState.Open then begin 
      Connection.Close(); 
    end 
  end; 
end; 

procedure TWFindex.MostrarFoto; 
Var 
  ReaderMostrarFoto : OdbcDataReader; 
  CommandMostrarFoto: OdbcCommand; 
  sMostrarFoto : System.Text.StringBuilder; 
begin 
  sMostrarFoto := System.Text.StringBuilder.Create(); 
  sMostrarFoto.Append(´SELECT noticia_foto.fotonot_arquivo, noticia_foto.fotonot_credito ´ + 
  ´FROM noticia_foto, noticia WHERE noticia.noticia_fotodestaque = noticia_foto.fotonot_id ´ + 
  ´AND noticia.noticia_id = ´ + noticiadestaqueid); 
  CommandMostrarFoto := OdbcCommand.Create(sMostrarFoto.ToString(), Connection); 
  try 
    Connection.Open(); 
    ReaderMostrarFoto := CommandMostrarFoto.ExecuteReader(); 
    ReaderMostrarFoto.Read(); 
    IMGDestaque.ImageUrl := ´imagensbd/282/´ + ReaderMostrarFoto.Item[´FOTONOT_ARQUIVO´].ToString; 
    lcredito.Text := ReaderMostrarFoto.Item[´FOTONOT_CREDITO´].ToString; 
    ReaderMostrarFoto.Close(); 
    Connection.Close(); 
  except 
    if Connection.State = ConnectionState.Open then begin 
      Connection.Close(); 
    end 
  end; 
end; 

procedure TWFindex.MostrarTodasNot; 
Var 
  ReaderTodasNoticias : OdbcDataReader; 
  CommandTodasNoticias: OdbcCommand; 
  sTodasNoticias : System.Text.StringBuilder; 
begin 
  sTodasNoticias := System.Text.StringBuilder.Create(); 
  sTodasNoticias.Append(´SELECT NOTICIA_ID, NOTICIA_DTCAD, NOTICIA_TITULO FROM ´ + 
    ´noticia ORDER BY noticia_dtcad DESC, noticia_id DESC LIMIT 0,5´); 
  CommandTodasNoticias := OdbcCommand.Create(sTodasNoticias.ToString(), Connection); 
  try 
    Connection.Open(); 
    ReaderTodasNoticias := CommandTodasNoticias.ExecuteReader(); 
    DGNoticias.DataSource := ReaderTodasNoticias; 
    DGNoticias.DataBind(); 
    ReaderTodasNoticias.Close(); 
    Connection.Close(); 
  except 
    if Connection.State = ConnectionState.Open then begin 
      Connection.Close(); 
    end 
  end; 
end;



Rzcoimbra

Rzcoimbra

Curtidas 0

Respostas

Rzcoimbra

Rzcoimbra

09/08/2005

qualquer situação que alguem poder apontar é valido.

obrigado


GOSTEI 0
POSTAR