求哪位帅哥帮帮忙,这段C#代码错在哪

来源:百度知道 编辑:UC知道 时间:2024/05/25 04:07:28
protected void btnAdd_Click(object sender, EventArgs e)
{

//新建连接对象
SqlConnection conn1 = new SqlConnection();
//从配置文件中获取信息
conn1.ConnectionString =
ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;

//新建命令对象
SqlCommand cmd1 = new SqlCommand();
cmd1.CommandText = "update Child set ChildName= '" + txtName.Text;
cmd1.CommandText += "' , Link = '" + txtxinghao.Text;
cmd1.CommandText += "' , region = '" + brigade.Text;
cmd1.CommandText += "' , sex = '" + txt5.Text;
cmd1.CommandText += "' , Contents = '" + zaishuiliang.Text;
cmd1.CommandText += "' , Child.CategoryName = '" + DropDownList1.SelectedItem.Text.Trim() +

cmd1.CommandText += "' , Child.CategoryName = '" + DropDownList1.SelectedItem.Text.Trim();
这句的错误

请把错误提示贴上来,这样找很难找。
_________________________________________
cmd1.CommandText += " where ID = " + this.contactID;
改成
cmd1.CommandText += " where ID = '" + this.contactID + "'";
试试。

另外你这两句
cmd1.CommandText += "' , Child.CategoryName = '" + DropDownList1.SelectedItem.Text.Trim() + "'";
cmd1.CommandText += "' , Child.CategoryID = '" + DropDownList1.SelectedItem.Value.Trim() + "'";
好像之间多了一对单引号。

太不规范了

‘10’附近有语法错误
字符串'wherer ID=39'后的引号不完整
where ID=39