protected void Button1_Click(object sender, EventArgs e) {string str = "Data Source=(local);Database=laomo;User ID=sa;Pwd=sa"; SqlConnection con = new SqlConnection(str); con.Open();//awarddateid, 没有设置 string peo = "insert into [name](name,sex,title,id,nation,polstatus,education,awardnameid,placeid,workplaceid) values = ('" + TextBox1.Text.ToString() + "','" + TextBox4.Text.ToString() + "','" + TextBox2.Text.ToString() + "','" + TextBox3.Text.ToString() + "','" + TextBox5.Text.ToString() + "','" + DropDownList1.SelectedValue.ToString() + "', '" + DropDownList6.SelectedValue.ToString() + "','" + DropDownList2.SelectedValue.ToString() + "','" + DropDownList4.SelectedValue.ToString() + "','" + DropDownList3.SelectedValue.ToString() + "')"; SqlCommand str1 = new SqlCommand(peo, con); str1.ExecuteNonQuery(); con.Close();}求大神解决 DropDownList4.SelectedValue 后面要不要加 .ToString() 这个的作用是什么?
2 回答
繁花不似锦
TA贡献1851条经验 获得超4个赞
调试一下peo这个参数,这个应该是sql语句拼错了 values = ('" 把=删了 直接是( ,DropDownList4.SelectedValue加不加无所谓因为已经是string类型了
慕容森
TA贡献1853条经验 获得超18个赞
comm.CommandText
=
string.Format("update
dianying
set
Piaoshu=Piaoshu-(Piaoshu='[0]'),
where
Id='[1]'",a,s);
这'[0]'和'[1]'加单引号和
中括号
干嘛?看表达式的意思应该是数字,改成:
comm.CommandText
=
string.Format("update
dianying
set
Piaoshu=Piaoshu-(Piaoshu=0),
where
Id=1",a,s);
添加回答
举报
0/150
提交
取消