C#语句中ExecuteReader()的作用,RadioButtonList的DataSource属性是什么意思?代码如下,求高人指点。 10
SqlCommandcmdItem=newSqlCommand("selectvoteDetailsID,voteItemfromvoteDetailswherevote...
SqlCommand cmdItem = new SqlCommand("select voteDetailsID,voteItem from voteDetails where voteID=" + this.voteID, con);
SqlDataReader sdr = cmdItem.ExecuteReader();//教程说这是产生一个游标,我不清楚具体结果是什么
this.rBtnItems.DataSource = sdr;//这句代码是什么意思不清楚,烦请指点 展开
SqlDataReader sdr = cmdItem.ExecuteReader();//教程说这是产生一个游标,我不清楚具体结果是什么
this.rBtnItems.DataSource = sdr;//这句代码是什么意思不清楚,烦请指点 展开
1个回答
展开全部
vote.aspx.cs
using System.Data .SqlClient ;
private string voteID="1";
private void Page_Load(object sender, System.EventArgs e)
{
if (! this.IsPostBack )
{
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmd= new SqlCommand ("select voteTitle from voteMaster where voteID=" + this.voteID,con );
string title=Convert.ToString ( cmd.ExecuteScalar());
this.lbl .Text =title;
SqlCommand cmdItem=new SqlCommand ("select voteDetailsID, voteItem from voteDetails where voteID=" +this.voteID ,con);
SqlDataReader sdr= cmdItem.ExecuteReader();
this.rBtnItems.DataSource =sdr;
this.rBtnItems .DataTextField="voteItem";
this.rBtnItems .DataValueField="voteDetailsID";
this.rBtnItems .DataBind ();
sdr.Close ();
con.Close();
// 在此处放置用户代码以初始化页面
}
以上主要为 显示页面的内容
private void btnVote_Click(object sender, System.EventArgs e)
{
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmd= new SqlCommand ();
cmd.Connection = con; //不懂
cmd.CommandText= "update voteDetails set voteNum= voteNum+1 where voteID="+ voteID+" and voteDetailsID="+ this.rBtnItems.SelectedValue.ToString();
cmd.ExecuteNonQuery();
con.Close ();
}
create trigger updateMaster
on voteDetails
for update
as
begin
update voteMaster set voteSum = voteSum+ 1 where top1 voteID= (selecte voteID from inserted)
end
以上主要为 投票事件, 数据库中引用到触发器
"结果按钮"将页面跳转至新页面"Result.aspx":
private void rBtnShowResult_Click(object sender, System.EventArgs e)
{
Response.Redirect ("Result.aspx?voteID="+ this.voteID );
}
新页面Result.aspx 才最终将数据库中的数据表现出来.并响应"投票"操作:
private void Page_Load(object sender, System.EventArgs e)
{
string voteID= Request.QueryString ["voteID"].ToString ();
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmdItem= new SqlCommand ("select * from voteDetails where voteID="+ voteID, con);
SqlDataReader sdr = cmdItem.ExecuteReader();
while(sdr.Read ())
{
Response.Write ("<font size=20>"+ sdr.GetString (2)+"-" +sdr.GetInt32 (3).ToString ()+"</font><br>");
}
using System.Data .SqlClient ;
private string voteID="1";
private void Page_Load(object sender, System.EventArgs e)
{
if (! this.IsPostBack )
{
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmd= new SqlCommand ("select voteTitle from voteMaster where voteID=" + this.voteID,con );
string title=Convert.ToString ( cmd.ExecuteScalar());
this.lbl .Text =title;
SqlCommand cmdItem=new SqlCommand ("select voteDetailsID, voteItem from voteDetails where voteID=" +this.voteID ,con);
SqlDataReader sdr= cmdItem.ExecuteReader();
this.rBtnItems.DataSource =sdr;
this.rBtnItems .DataTextField="voteItem";
this.rBtnItems .DataValueField="voteDetailsID";
this.rBtnItems .DataBind ();
sdr.Close ();
con.Close();
// 在此处放置用户代码以初始化页面
}
以上主要为 显示页面的内容
private void btnVote_Click(object sender, System.EventArgs e)
{
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmd= new SqlCommand ();
cmd.Connection = con; //不懂
cmd.CommandText= "update voteDetails set voteNum= voteNum+1 where voteID="+ voteID+" and voteDetailsID="+ this.rBtnItems.SelectedValue.ToString();
cmd.ExecuteNonQuery();
con.Close ();
}
create trigger updateMaster
on voteDetails
for update
as
begin
update voteMaster set voteSum = voteSum+ 1 where top1 voteID= (selecte voteID from inserted)
end
以上主要为 投票事件, 数据库中引用到触发器
"结果按钮"将页面跳转至新页面"Result.aspx":
private void rBtnShowResult_Click(object sender, System.EventArgs e)
{
Response.Redirect ("Result.aspx?voteID="+ this.voteID );
}
新页面Result.aspx 才最终将数据库中的数据表现出来.并响应"投票"操作:
private void Page_Load(object sender, System.EventArgs e)
{
string voteID= Request.QueryString ["voteID"].ToString ();
SqlConnection con= DB.creatConnetion();
con.Open ();
SqlCommand cmdItem= new SqlCommand ("select * from voteDetails where voteID="+ voteID, con);
SqlDataReader sdr = cmdItem.ExecuteReader();
while(sdr.Read ())
{
Response.Write ("<font size=20>"+ sdr.GetString (2)+"-" +sdr.GetInt32 (3).ToString ()+"</font><br>");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询