quinta-feira, 23 de fevereiro de 2012

Código fonte para o exercício Listagem de Clientes em ASP.Net e C#


Código fonte  do arquivo listaclientes.asp.cs
Para que você possa testar este programa carregue o banco de dados no link abaixo
Mala direta

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

namespace primeirosite
{
    public partial class listaclientes : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MySqlConnection conn;
            string conexao = "Server=localhost; UserId=root; Password=; Database=maladireta;";
            conn = new MySqlConnection(conexao);
            string comando = "select id,nome,telefone from contato order by nome";
            MySqlCommand cmd = new MySqlCommand(comando);
            cmd.Connection = conn;
            conn.Open();
            MySqlDataReader dr;
            dr = cmd.ExecuteReader();
            Response.Write("<form id=\"form1\" runat=\"server\"><div>");
            Response.Write("<table style=\"width:100%\">");
            Response.Write("<tr><td colspan=\"4\" style=\"text-align: center\">");
            Response.Write("Listagem de Contatos</td>");
            Response.Write("</tr>");
            Response.Write("<tr>");
            Response.Write("<td class=\"style4\">");
            Response.Write("<asp:CheckBox ID=\"deleta\" runat=\"server\"/>");
            Response.Write("</td>");
            Response.Write("<td class=\"style2\">");
            Response.Write("Id</td>");
            Response.Write("<td class=\"style3\">");
            Response.Write("Nome</td>");
            Response.Write("<td style=\"text-align: center\">");
            Response.Write("Telefone</td>");
            Response.Write("</tr>");
            while (dr.Read()) {
                Response.Write("<tr>");
                Response.Write("<td class=\"style4\">&nbsp;</td>");
                Response.Write("<td class=\"style2\">"+dr["id"]+"</td>");
                Response.Write("<td class=\"style3\">"+dr["nome"]+"</td>");
                Response.Write("<td>" + dr["telefone"] + "</td></tr>");
            }
            conn.Close();
            Response.Write("</table>");
            Response.Write("</div></form>");
        }
    }
}

listaclientes.asp


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="listaclientes.aspx.cs" Inherits="primeirosite.listaclientes" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
        }
        .style2
        {
            width: 42px;
            text-align: left;
        }
        .style3
        {
            width: 641px;
            text-align: left;
        }
        .style4
        {
            width: 74px;
        }
    </style>
</head>
<body>

</body>
</html>


Nenhum comentário:

Postar um comentário

Obrigado por contribuir para melhorar este blog, deixe sua mensagem.
Forte Abraço