关键字where附近有语法错误
本帖最后由 k1014247445 于 2013-08-30 08:44:02 编辑 大家好,我这有一段用于更新的方法。
protected void updateBTN_Click(object sender, EventArgs e)
{
SqlParameter[] commandParameters = new SqlParameter[] { new SqlParameter("@id", base.Request.QueryString["id"]), new SqlParameter("@staffcode", this.staffcode.Text), new SqlParameter("@dept", this.dept.Text), new SqlParameter("@intro", this.intro.Text), new SqlParameter("@image_big", this.image_big.Text), new SqlParameter("@image_small", this.image_small.Text), new SqlParameter("@orderid", this.orderid.Text), new SqlParameter("@poid", this.ddl_archives.SelectedItem.Value) };
string commandText = "\r\n update po_staff set \r\n staffcode=@staffcode,\r\n intro=@intro, \r\n image_small=@image_small, \r\n image_big=@image_big,\r\n dept=@dept,\r\n orderid=@orderid,\r\n poid=@poid,\r\n where id=@id\r\n ";
DALHelper.ExecuteNonQuery(DALHelper.GetCon(), CommandType.Text, commandText, commandParameters);
Helper.Result(this, "操作成功", "stafflist.aspx");
}
}
但是点击更新时错误
关键字where附近有语法错误
大家能否帮忙看下sql语句哪里出错了吗
新手谢谢了
[解决办法]
目测多一个逗号
[解决办法]
where 前那个逗号是不需要的
------解决方案--------------------
poid=@poid,
[解决办法]
poid=@poid,\r\n where
where前的\r\n前有个逗号
[解决办法]
遇到这种问题断点调试,拿到commandText在数据库中查询下
[解决办法]
眼神如此的差,教你字符串要这么写:
string commandText = @"
update po_staff set
staffcode=@staffcode,
intro=@intro,
image_small=@image_small,
image_big=@image_big,
dept=@dept,
orderid=@orderid,
poid=@poid
where id=@id";
[解决办法]
这种问题 ,断点调试 把生成的数据库语言 拷出来一看不就全明白了么
[解决办法]
poid=@poid,\r\n
改成poid=@poid \r\n