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
提交
取消