"="附近有语法错误.str1.ExecuteNonQuery();该怎么办?

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() 这个的作用是什么?

qq_笑_17
浏览 557回答 2
2回答

繁花不似锦

调试一下peo这个参数,这个应该是sql语句拼错了 values = ('" 把=删了 直接是( ,DropDownList4.SelectedValue加不加无所谓因为已经是string类型了

慕容森

comm.CommandText=string.Format("updatedianyingsetPiaoshu=Piaoshu-(Piaoshu='[0]'),whereId='[1]'",a,s);这'[0]'和'[1]'加单引号和中括号干嘛?看表达式的意思应该是数字,改成:comm.CommandText=string.Format("updatedianyingsetPiaoshu=Piaoshu-(Piaoshu=0),whereId=1",a,s);
打开App,查看更多内容
随时随地看视频慕课网APP