zoukankan      html  css  js  c++  java
  • 投票系统前台 C#,数据库SQL

    ------------vote.aspx.cs--------------------

      private void Page_Load(object sender, System.EventArgs e)
      {
       // 在此处放置用户代码以初始化页面
       if(!Page.IsPostBack)
       {
        SqlConnection con=db.createrConnection();
        con.Open();
        SqlCommand cmd=new SqlCommand("select votetitle from votemaster where voteid="+this.idd,con);
        string title=Convert.ToString(cmd.ExecuteScalar());
        this.title.Text=title;
        cmd.CommandText="select * from vote where voteid="+this.idd;
        SqlDataReader sdr=cmd.ExecuteReader();
        this.rad.DataSource=sdr;
        this.rad.DataTextField="voteitem";
        this.rad.DataValueField="id";
        this.rad.DataBind();
        sdr.Close();
        con.Close();
       }
      }
    窗体代码
    private void tp_Click(object sender, System.EventArgs e)
      {
      SqlConnection con=db.createrConnection();
      con.Open();
      SqlCommand cmd=new SqlCommand();
      cmd.Connection=con;
      cmd.CommandText="update vote set votenun=votenun+1 where voteid="+this.idd+" and id="+this.rad.SelectedValue.ToString();
      cmd.ExecuteNonQuery();
     con.Close();
       

      }

      private void show_Click(object sender, System.EventArgs e)
      {
       Response.Redirect("show.aspx?voteid="+this.idd);
      }
     }
    }
    ---------------------完----------vote.aspx -----------------

     

    Label
     
    ------------------------------完-----------db.cs-----------------------

       // TODO: 在此处添加构造函数逻辑
       //
      }
      public static SqlConnection createrConnection()
      {
     SqlConnection con=new SqlConnection("server=.;database=vote;uid=sa;pwd=980123");
      return con;
      }
     }
    }
    ------------------------show.aspx.cs--------------------------
    private void Page_Load(object sender, System.EventArgs e)
      {
       string id=Request.QueryString["voteid"].ToString();
       SqlConnection con=db.createrConnection();
       con.Open();
       SqlCommand cmd=new SqlCommand("select * from vote where voteid="+id,con);
       SqlDataReader sdr=cmd.ExecuteReader();
       while (sdr.Read())
      {
      Response.Write(sdr.GetString(2)+"--"+sdr.GetInt32(3).ToString());
      }
    ---------------------完-------------sql文件------------------

    create database vote

    use vote

    create table votemaster
    (
    voteid int primary key,--投票编号
    votetitle varchar(100) not null,--投票标题
    votesum int default 0 --投票的总票数
    )

    insert into votemaster values(1,'书记选举',0)
    insert into votemaster values(2,'市长选举',0)

    select * from votemaster

    create table vote
    (
     voteid int foreign key references votemaster(voteid),--该键是主表的联系键
     id int not null,
     voteitem varchar(20) not null,
     votenun int default 0,
    )

    insert into vote values(1,1,'张三',0)
    insert into vote values(1,2,'李达',0)
    insert into vote values(1,3,'钟馗',0)
    insert into vote values(1,4,'江尚',0)
    insert into vote values(2,1,'刘文采',0)
    insert into vote values(2,2,'李世民',0)
    insert into vote values(2,3,'周正',0)
    insert into vote values(2,4,'张三疯',0)

    select * from vote where voteid=2

    create trigger updatemaster--这里是触发器
    on vote
    for update
    as begin
      update votemaster set votesum=votesum+1 where voteid=(select top 1 voteid from inserted)
    end


    update vote set votenun=votenun+1 where voteid=2 and id=2

    ------------------------------完--------------------

  • 相关阅读:
    基于稀疏表示学习的图像分类
    多个for循环嵌套会影响速度
    LP-KPN
    C++ const
    C++面向对象
    使用最新的“huihui中文语音库”实现文本转语音功能
    后缀crt证书转换
    server2012 配置SSL证书
    解决windows server2012 评估版本过期,系统会自动关机
    Win2008 r2 IIS7.5出现FastCGI进程最近常常失败。请过一会再尝试此请求的解决方法
  • 原文地址:https://www.cnblogs.com/thcjp/p/349892.html
Copyright © 2011-2022 走看看