主题:奇怪的问题
我在用GridView的编辑列做更新的时候出现了一个奇怪的问题
第 1 行: 'where productTypeID=' 附近有语法错误。
字符串 '' 之前有未闭合的引号
代码如下:
protected void BindTogvProductType()
{
con.Open();
string sqlstrType = "select * from T_ProductType";
gvProductType.DataKeyNames = new string[] { "productTypeID" };
SqlDataAdapter sdaType = new SqlDataAdapter(sqlstrType, con);
DataSet dsType = new DataSet();
sdaType.Fill(dsType);
gvProductType.DataSource = dsType;
gvProductType.DataBind();
con.Close();
}
protected void gvProductType_RowEditing(object sender, GridViewEditEventArgs e)
{
GridViewRow gvr = gvProductType.Rows[e.NewEditIndex];
this.gvProductType.EditIndex = gvr.RowIndex;
BindTogvProductType();
}
protected void gvProductType_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.gvProductType.EditIndex = -1;
BindTogvProductType();
}
protected void gvProductType_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
con.Open();
GridViewRow gvr = gvProductType.Rows[e.RowIndex];
string productTypeID = this.gvProductType.DataKeys[e.RowIndex].ToString();
string productTypeName = ((TextBox)(gvr.Cells[1].Controls[0])).Text.Trim();
string sqlstrUpdate = "update T_ProductType set productTypeName=" + productTypeName + "'where productTypeID='" + productTypeID + "'";
SqlCommand cmdUpdate = new SqlCommand(sqlstrUpdate, con);
cmdUpdate.ExecuteNonQuery();
this.gvProductType.EditIndex = -1;
con.Close();
BindTogvProductType();
}
第 1 行: 'where productTypeID=' 附近有语法错误。
字符串 '' 之前有未闭合的引号
代码如下:
protected void BindTogvProductType()
{
con.Open();
string sqlstrType = "select * from T_ProductType";
gvProductType.DataKeyNames = new string[] { "productTypeID" };
SqlDataAdapter sdaType = new SqlDataAdapter(sqlstrType, con);
DataSet dsType = new DataSet();
sdaType.Fill(dsType);
gvProductType.DataSource = dsType;
gvProductType.DataBind();
con.Close();
}
protected void gvProductType_RowEditing(object sender, GridViewEditEventArgs e)
{
GridViewRow gvr = gvProductType.Rows[e.NewEditIndex];
this.gvProductType.EditIndex = gvr.RowIndex;
BindTogvProductType();
}
protected void gvProductType_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.gvProductType.EditIndex = -1;
BindTogvProductType();
}
protected void gvProductType_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
con.Open();
GridViewRow gvr = gvProductType.Rows[e.RowIndex];
string productTypeID = this.gvProductType.DataKeys[e.RowIndex].ToString();
string productTypeName = ((TextBox)(gvr.Cells[1].Controls[0])).Text.Trim();
string sqlstrUpdate = "update T_ProductType set productTypeName=" + productTypeName + "'where productTypeID='" + productTypeID + "'";
SqlCommand cmdUpdate = new SqlCommand(sqlstrUpdate, con);
cmdUpdate.ExecuteNonQuery();
this.gvProductType.EditIndex = -1;
con.Close();
BindTogvProductType();
}