投票系统前台 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
------------------------------完--------------------
投票系统前台 C#,数据库SQL的更多相关文章
- SSM框架整合项目 :投票系统
框架: Spring SpringMVC MyBatis 题目: 投票系统 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastjson 5, aspe ...
- SSM demo :投票系统
框架: Spring SpringMVC MyBatis 题目: 投票系统 导包: 1, spring 2, MyBatis 3, mybatis-spring 4, fastjson 5, aspe ...
- Django写的投票系统2(转)
在上一篇中 django实例:创建你的第一个应用投票系统(一) 已经介绍基本的功能,并已经启动服务了.这一节介绍数据库相关的东东. 首页打开mysite/settings.py配置文件, 设置数据库打 ...
- Django写的投票系统1(转)
当然主要是从django的帮助文档里面来的,权当是翻译吧 这个投票系统的主要功能有 1.一个前台页面,可以让用户来投票 2.一个管理员页面,可以用来添加.修改.删除投票 首页第一步要确定你已经安装了D ...
- log4j向oracle中插入一条系统当前时间的sql语句
配置log4j,要向oracle插入一条系统当前时间的sql语句,按网上查找的总是出现各种各样的报错,最后总结出的写法是: ### shezhi### log4j.rootLogger = debug ...
- Django快速开发之投票系统
https://docs.djangoproject.com/en/1.8/intro/tutorial01/ 参考官网文档,创建投票系统. ================ Windows 7/1 ...
- Android 系统API实现数据库的增删改查和SQLite3工具的使用
在<Android SQL语句实现数据库的增删改查>中介绍了使用sql语句来实现数据库的增删改查操作,本文介绍Android 系统API实现数据库的增删改查和SQLite3工具的使用. 系 ...
- linux系统上Mysql数据库导入导出操作
需求:把MySQL数据库目录中的dz数据库备份到/home/dz_bak.sql ,然后再新建一个数据库dzbak,最后把/home/dz_bak.sql 导入到数据库dzbak中.操作如下:以下操作 ...
- 数据库 SQL语句优化
温馨提示:本篇内容均来自网上,本人只做了稍微处理,未进行细致研究,仅当做以后不备之需,如若你喜欢可尽情转走. 一.问题的提出 在应用系统开发初期,由于开发数据库数据比较少,对于查询SQL语句,复杂视图 ...
随机推荐
- iOS开发宝典:String用法大全
一.NSString 创建字符串. NSString *astring = @"This is a String!"; 创建空字符串,给予赋值. NSString *astri ...
- ASPxGridView后台获取edit、delete、选择框等按钮。
GridViewCommandColumn commandColumn = (GridViewCommandColumn)ASPxGridViewInstance.Columns["#&qu ...
- vector中resize和reserve的区别,代码验证
#include <vector> using namespace std; int main() { vector<int> resizeVect; vector<in ...
- 使用wininet向FTP服务器发送文件
.h #pragma once #include <windows.h> #include <tchar.h> #include <string> #include ...
- [NOIP1999提高] CODEVS 1047 邮票面值设计(dfs+dp)
dfs出邮票的各种面值,然后dp求解. ------------------------------------------------------------------------------- ...
- 托管服务帐号(Managed Service Account)
托管服务帐号是绑定到单独的机器上,并且仅用于服务所用,所以不能用来登录. 创建托管帐号,不需要指定密码,密码会由活动目录自动管理.并且根据密码策略(默认30天)自动刷新,期间不影响服务. 在创建完之后 ...
- python中3个帮助函数help、dir、type的使用
1.help函数:查看模块.函数.变量的详细说明: 查看模块 help("modules") 查看包 help("json") 查看类 help(json.J ...
- app 转caf 音频 代码
afconvert /Users/xiaoye/Downloads/cat.caf /Users/xiaoye/Downloads/cat1.caf -d ima4 -f caff -v;
- perl lwp关闭ssl校验
use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; use HTTP::Response; use Encode; use File:: ...
- kinect for windows - 手势识别之一,kinect手势识别框架
何为手势识别,就是电脑认识人手的自然动作.自然动作包括摆手,握拳,双手合十等等.如果电脑能认识我们这些手势,将来的人机交互将会变得简单而有趣.这里手势不等同于某些规定的动作,比如按鼠标左键,则不属于手 ...