protected void Button1_Click(object sender, EventArgs e)
{
// int a = Convert.ToInt32(this.RadioButtonList1.SelectedValue);
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Title set titleID=Convert.ToInt32(this.RadioButtonList1.SelectedValue)";
cmd.ExecuteNonQuery();
con.Close();
}
}
提示我“。”附近有错误。不知道是update写错了还是怎么了。
之前我弄了个RadioButtonList,我想获得被选中项的this.RadioButtonList1.DataValueField的值,不知道this.RadioButtonList1.SelectedValue是不是这个值。我想用这个值更新一下下面的表
create table Title
(
id int primary key, --编号
titleID int default 1 not null --投票的标题序号
)insert into Title values(1,1)之前还有一段我绑定控件的代码: protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select * from voteMaster",con);
SqlDataReader sdr = cmd.ExecuteReader();
this.RadioButtonList1.DataTextField = "voteTitle";
this.RadioButtonList1.DataValueField = "voteID";
this.RadioButtonList1.DataSource = sdr;
this.RadioButtonList1.DataBind();
sdr.Close();
con.Close();
}我就是想实现用voteMaster表中的voteID的值去更新Title表中的titleID。好心人帮帮忙吧,先谢了。
{
// int a = Convert.ToInt32(this.RadioButtonList1.SelectedValue);
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Title set titleID=Convert.ToInt32(this.RadioButtonList1.SelectedValue)";
cmd.ExecuteNonQuery();
con.Close();
}
}
提示我“。”附近有错误。不知道是update写错了还是怎么了。
之前我弄了个RadioButtonList,我想获得被选中项的this.RadioButtonList1.DataValueField的值,不知道this.RadioButtonList1.SelectedValue是不是这个值。我想用这个值更新一下下面的表
create table Title
(
id int primary key, --编号
titleID int default 1 not null --投票的标题序号
)insert into Title values(1,1)之前还有一段我绑定控件的代码: protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = DB.createConnection();
con.Open();
SqlCommand cmd = new SqlCommand("select * from voteMaster",con);
SqlDataReader sdr = cmd.ExecuteReader();
this.RadioButtonList1.DataTextField = "voteTitle";
this.RadioButtonList1.DataValueField = "voteID";
this.RadioButtonList1.DataSource = sdr;
this.RadioButtonList1.DataBind();
sdr.Close();
con.Close();
}我就是想实现用voteMaster表中的voteID的值去更新Title表中的titleID。好心人帮帮忙吧,先谢了。
拿出来
cmd.CommandText = "update Title set titleID='"+Convert.ToInt32(this.RadioButtonList1.SelectedValue)+"'";
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Title set titleID="+Convert.ToInt32(this.RadioButtonList1.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
}
cmd.CommandText = "update Title set titleID=‘“+Convert.ToInt32(this.RadioButtonList1.SelectedValue)+”’";
4楼的可以,其他的不行,提示说是字符串错误。
还有就是this.RadioButtonList1.SelectedValue表示的是什么?我想得到的是voteID的值,我运行后,
Title
表中的
titleID被清零了,本来应该是2的,
我再问个问题怎么从被选项中得到voteID的值呢?我想用它更新用啊。
这么写还是会提示字符串格式错误啊
'"+Convert.ToInt32(this.RadioButtonList1.SelectedValue)+"'或者是
sql="update Title set titleID="+Convert.ToInt32(this.RadioButtonList1.SelectedValue);
BindData();
否则页面回传
{
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "update Title set titleID='"+this.RadioButtonList1.SelectedValue+"'";//titleID的值
cmd.ExecuteNonQuery();
con.Close();
}