首页 > 解决方案 > 表的行内容似乎在更新时没有改变

问题描述

我试图在编辑时更新表格的行,但它似乎并没有改变行内容。

下面给出的是我的更新功能。有什么我想念的吗?到目前为止没有错误显示。我已经引用了很多在此之前发布的文章和问题,但似乎没有一个解决方案有效。

protected void GridIntegrations_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    try
    {
        String name = Globals.sheet;
        String constr = Globals.intFile;

        String intNo = GridIntegrations.Rows[e.RowIndex].FindControl("lbl_intno")!=null? (GridIntegrations.Rows[e.RowIndex].FindControl("lbl_intno") as Label).Text:null;
        TextBox intTitle = GridIntegrations.Rows[e.RowIndex].FindControl("txtIntegrationTitle") as TextBox;
        TextBox state = GridIntegrations.Rows[e.RowIndex].FindControl("txtState") as TextBox;
        TextBox businessOwner = GridIntegrations.Rows[e.RowIndex].FindControl("txtBusinessOwner") as TextBox;
        TextBox businessSegment = GridIntegrations.Rows[e.RowIndex].FindControl("txtBusinessSegment") as TextBox;
        TextBox legacyId = GridIntegrations.Rows[e.RowIndex].FindControl("txtLegacyID") as TextBox;
        OleDbConnection con = new OleDbConnection(constr);
        con.Open();
        OleDbCommand oconn = new OleDbCommand("UPDATE [" + name + "$] SET [Business Owner] = ? WHERE [Integration No#] = ?", con);

        oconn.Parameters.AddWithValue("Business Owner", businessOwner.Text);
        if (String.IsNullOrWhiteSpace(intNo) == false)
            oconn.Parameters.AddWithValue("Integration No#", intNo);
        else
            oconn.Parameters.AddWithValue("Integration No#", DBNull.Value);


        oconn.ExecuteNonQuery();
        con.Close();
        GridIntegrations.EditIndex = -1;
        BindData();
        lblSuccessMessage.Text = "Selected Record Updated";
        lblErrorMessage.Text = "";
    }
    catch (Exception ex)
    {
        lblSuccessMessage.Text = "";
        lblErrorMessage.Text = ex.Message;
    }
    }

标签: c#asp.netasp.net-web-api

解决方案


这很好用!希望它对未来的人有所帮助,欢迎您。:)

protected void GridIntegrations_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                String name = Globals.sheet;
                String constr = Globals.intFile;


                Label intNo = GridIntegrations.Rows[e.RowIndex].FindControl("lbl_intno") as Label;//GridIntegrations.Rows[e.RowIndex].FindControl("lbl_intno")!=null? (GridIntegrations.Rows[e.RowIndex].FindControl("lbl_intno") as Label).Text:null;
                TextBox intTitle = GridIntegrations.Rows[e.RowIndex].FindControl("txtIntegrationTitle") as TextBox;
                TextBox state = GridIntegrations.Rows[e.RowIndex].FindControl("txtState") as TextBox;
                TextBox businessOwner = GridIntegrations.Rows[e.RowIndex].FindControl("txtBusinessOwner") as TextBox;
                TextBox businessSegment = GridIntegrations.Rows[e.RowIndex].FindControl("txtBusinessSegment") as TextBox;
                TextBox legacyId = GridIntegrations.Rows[e.RowIndex].FindControl("txtLegacyID") as TextBox;
                OleDbConnection con = new OleDbConnection(constr);
                con.Open();
                OleDbCommand oconn = new OleDbCommand("UPDATE [" + name + "$] SET [Integration Title] = '" + intTitle.Text + "',[State] = '" + state.Text + "',[Business Owner] = '" + businessOwner.Text + "',[Business Segment] = '" + businessSegment.Text + "',[Legacy ID] = '" + legacyId.Text + "' WHERE [Integration No#] = '" + intNo.Text + "'", con);
                
                oconn.ExecuteNonQuery();
                con.Close();
                GridIntegrations.EditIndex = -1;
                BindData();
                lblSuccessMessage.Text = "Selected Record Updated";
                lblErrorMessage.Text = "";
            }
            catch (Exception ex)
            {
                lblSuccessMessage.Text = "";
                lblErrorMessage.Text = ex.Message;
            }
        }

推荐阅读