很郁闷呀,大家帮我看看是啥毛病吧,还是修改不了
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack )
{SqlConnection con=DB.createConnection ();
con.Open();
SqlCommand cmd=new SqlCommand ( "select votetitle from votemaster where voteid= "+voteid,con);
this.lbshowtitle.Text =Convert.ToString (cmd.ExecuteScalar ());
SqlCommand cmditems=new SqlCommand ( "select votedetailsid,voteitems from votedetails where voteid= "+this.voteid ,con);
SqlDataReader reader=cmditems.ExecuteReader ();
this.rbtnlist .DataSource =reader;
this.rbtnlist .DataTextField = "voteitems ";
this.rbtnlist .DataValueField = "votedetailsid ";
this.rbtnlist .DataBind ();
reader.Close ();
}上面这是初始化,将表中的记录绑定到radiobuttonlist上,绑定成功
下面这段我是想点击radiobutton选项,再点击votebtn按钮,实现修改数据库记录的值,就是不行
private void btnvote_Click(object sender, System.EventArgs e)
{
SqlConnection con=DB.createConnection ();
con.Open ();
SqlCommand cmd=new SqlCommand ();
cmd.Connection =con;
cmd.CommandText = "update votedetails set votesum=votesum+1 where voteid= "+voteid+ " and votedetailsid= "+this.rbtnlist .SelectedValue .ToString ();
cmd.ExecuteNonQuery ();
con.Close ();
望高手能详细指点一下,谢谢啦,今天真的好郁闷,一上午都没查出毛病
[解决办法]
SqlCommand cmditems=new SqlCommand ( "select votedetailsid,voteitems from votedetails where voteid= "+this.voteid ,con);
SqlDataReader reader=cmditems.ExecuteReader ();
this.rbtnlist .DataSource =reader;
this.rbtnlist .DataTextField = "voteitems ";
this.rbtnlist .DataValueField = "votedetailsid ";
this.rbtnlist .DataBind ();
建议用DataTable绑定到控件, SqlDataReader好象不太合适, 那对象是要Read的.