展开全部
在这62616964757a686964616fe58685e5aeb931333231376361里你必须在你 的计算机上采用 SQL Server 建立几张表 语法如下;
use zzyy
select * from votetitle
alter table votetitle add votenum int default 0 not null
alter table votetitle drop column votenum
update votetitle set votenum=0
create table vote
(
voteid int foreign key references votetitle(id),
voteitemid int not null,
voteitem varchar(50) not null,
notenum int default 0,
primary key(voteid,voteitemid)
)
select * from vote
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(2,1,'很好',0)
insert into vote values(2,2,'还行',0)
insert into vote values(2,3,'需要改进',0)
use zzyy
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
SqlConnection cnn=new SqlConnection("server=.;database=zzyy;uid=sa;pwd=;");
cnn.Open();
SqlCommand cmm=new SqlCommand("select votetitle from votetitle where id="+votetype.ToString(),cnn);
string title=cmm.ExecuteScalar().ToString();
this.Label1.Text=title;
SqlCommand cmm1=new SqlCommand("select voteitemid,voteitem from vote where voteid="+votetype.ToString(),cnn);
SqlDataReader sdr=cmm1.ExecuteReader();
this.RadioButtonList1.DataSource=sdr;
this.RadioButtonList1.DataTextField="voteitem";
this.RadioButtonList1.DataValueField="voteitemid";
this.RadioButtonList1.DataBind();
sdr.Close();
cnn.Close();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection cnn=new SqlConnection("server=.;database=zzyy;uid=sa;pwd=;");
cnn.Open();
SqlCommand cmm=new SqlCommand("update vote set notenum=notenum+1 where voteid="+
this.votetype.ToString()+" and voteitemid="+this.RadioButtonList1.SelectedValue.ToString(),cnn);
cmm.ExecuteNonQuery();
SqlCommand cmm1=new SqlCommand("update votetitle set votenum=votenum+1 where id="+
this.votetype.ToString(),cnn);
cmm1.ExecuteNonQuery();
cnn.Close();
}
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
protected System.Web.UI.WebControls.Button Button2;
int votetype=2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
SqlConnection cnn=new SqlConnection("server=.;database=zzyy;uid=sa;pwd=;");
cnn.Open();
SqlCommand cmm=new SqlCommand("select votetitle from votetitle where id="+votetype.ToString(),cnn);
string title=cmm.ExecuteScalar().ToString();
this.Label1.Text=title;
SqlCommand cmm1=new SqlCommand("select voteitemid,voteitem from vote where voteid="+votetype.ToString(),cnn);
SqlDataReader sdr=cmm1.ExecuteReader();
this.RadioButtonList1.DataSource=sdr;
this.RadioButtonList1.DataTextField="voteitem";
this.RadioButtonList1.DataValueField="voteitemid";
this.RadioButtonList1.DataBind();
sdr.Close();
cnn.Close();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection cnn=new SqlConnection("server=.;database=zzyy;uid=sa;pwd=;");
cnn.Open();
SqlCommand cmm=new SqlCommand("update vote set notenum=notenum+1 where voteid="+
this.votetype.ToString()+" and voteitemid="+this.RadioButtonList1.SelectedValue.ToString(),cnn);
cmm.ExecuteNonQuery();
// SqlCommand cmm1=new SqlCommand("update votetitle set votenum=votenum+1 where id="+
// this.votetype.ToString(),cnn);
//
// cmm1.ExecuteNonQuery();
cnn.Close();
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("show.aspx?voteid="+this.votetype.ToString());
}
}
public class show : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string id=this.Request.QueryString["voteid"].ToString();
SqlConnection cnn=new SqlConnection("server=.;database=zzyy;uid=sa;pwd=;");
cnn.Open();
SqlCommand cmm=new SqlCommand("select * from vote where voteid="+id,cnn);
SqlDataReader sdr=cmm.ExecuteReader();
while(sdr.Read())
{
Response.Write("ok"+sdr.GetString(2)+"--"+sdr.GetSqlInt32(3)+"
");
}
}
已赞过
已踩过<
你对这个回答的评价是?
评论
收起