c# - 表的行内容似乎在更新时没有改变
问题描述
我试图在编辑时更新表格的行,但它似乎并没有改变行内容。
下面给出的是我的更新功能。有什么我想念的吗?到目前为止没有错误显示。我已经引用了很多在此之前发布的文章和问题,但似乎没有一个解决方案有效。
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;
}
}
解决方案
这很好用!希望它对未来的人有所帮助,欢迎您。:)
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;
}
}
推荐阅读
- python - 如何在课堂上修复 TypeError
- c# - spa页面刷新时的asp-action url不正确
- logging - 删除多个目录中某个日期之前的文件
- asp.net - 应用程序的任何非有效用户都可以通过将其绝对 URL 直接输入浏览器 ASP.net 来访问 PDF 帮助文件
- python - 机场数据 - 我如何抓取数据并维护层次结构?
- java - 尝试并行化快速排序以在 Java 中的多个线程上运行
- excel - MXXML2.IVBSAXlexicalHandler_startCDATA未检测到词法
- java - 从任务访问异步方法参数或方法的注释
- javascript - 如何在脚本标签的 index.html 中使用 Bowser Javascript 库?
- sql - 将两列数据连接到新列中