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, 沒(méi)有設(shè)置 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() 這個(gè)的作用是什么?
2 回答

繁花不似錦
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
調(diào)試一下peo這個(gè)參數(shù),這個(gè)應(yīng)該是sql語(yǔ)句拼錯(cuò)了 values = ('" 把=刪了 直接是( ,DropDownList4.SelectedValue加不加無(wú)所謂因?yàn)橐呀?jīng)是string類型了

慕容森
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
comm.CommandText
=
string.Format("update
dianying
set
Piaoshu=Piaoshu-(Piaoshu='[0]'),
where
Id='[1]'",a,s);
這'[0]'和'[1]'加單引號(hào)和
中括號(hào)
干嘛?看表達(dá)式的意思應(yīng)該是數(shù)字,改成:
comm.CommandText
=
string.Format("update
dianying
set
Piaoshu=Piaoshu-(Piaoshu=0),
where
Id=1",a,s);
添加回答
舉報(bào)
0/150
提交
取消