
C# '=' 附近有语法错误。
protectedvoidGridView1_RowEditing(objectsender,GridViewEditEventArgse){GridView1.Edit...
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
this.bind();
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ID = Convert.ToInt32(GridView1 .DataKeys [e.RowIndex].Value.ToString ());
string userName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
string userPwd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
string sqlStr = "updatetb_user set username='"+userName +"userpwd="+userPwd+"' where ID="+ID;
string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myCon = new SqlConnection(myStr);
myCon.Open();
SqlCommand mySdr = new SqlCommand(sqlStr ,myCon );
mySdr.ExecuteNonQuery();
mySdr.Dispose();
myCon.Close();
GridView1.EditIndex = -1;
this.bind();
}
就是在更新的时候有问题。 展开
{
GridView1.EditIndex = e.NewEditIndex;
this.bind();
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ID = Convert.ToInt32(GridView1 .DataKeys [e.RowIndex].Value.ToString ());
string userName = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString();
string userPwd = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString();
string sqlStr = "updatetb_user set username='"+userName +"userpwd="+userPwd+"' where ID="+ID;
string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myCon = new SqlConnection(myStr);
myCon.Open();
SqlCommand mySdr = new SqlCommand(sqlStr ,myCon );
mySdr.ExecuteNonQuery();
mySdr.Dispose();
myCon.Close();
GridView1.EditIndex = -1;
this.bind();
}
就是在更新的时候有问题。 展开
4个回答
展开全部
string sqlStr = "updatetb_user set username='"+userName +"userpwd="+userPwd+"' where ID="+ID;
假如 username 是 abc
userpwd 是 123
ID 是 100
最后的 SQL 是
updatetb_user set username='abcuserpwd=123' where ID=100
理论上的SQL应该是
update b_user set username='abc', userpwd='123' where ID=100
是不是缺少一个逗号的原因?
假如 username 是 abc
userpwd 是 123
ID 是 100
最后的 SQL 是
updatetb_user set username='abcuserpwd=123' where ID=100
理论上的SQL应该是
update b_user set username='abc', userpwd='123' where ID=100
是不是缺少一个逗号的原因?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-13
展开全部
漏了几个符号,更正如下
string sqlStr = "updatetb_user set username='"+userName +"',userpwd='"+userPwd+"' where ID="+ID;
string sqlStr = "updatetb_user set username='"+userName +"',userpwd='"+userPwd+"' where ID="+ID;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sql语句有误,仔细检查SQL语句。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
string sqlStr = "updatetb_user set username="+userName +",userpwd="+userPwd+" where ID="+ID;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询