标签云

微信群

扫码加入我们

WeChat QR Code

All the research I've done seems to indicate that if I simply call DataBind() again then my gridview will get updated.This only seems to be the case if I'm debugging and stepping through my code, the gridview refreshes fine.However, if I don't step through my code while running the app in debug mode, the btnFileImport_Click method below doesn't refresh my gridview.Could it have anything to do with the fact that I'm updating the data the gridview uses by loading a file using an SSIS package?Below is the codebehind:namespace InternationalWires{public partial class Default_Corporate : System.Web.UI.Page{SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());SqlCommand cmd = null;SqlServerAgent sqlAgent = new SqlServerAgent();protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){BindRatesGrid();}}public void BindRatesGrid(){conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());SqlDataAdapter da = new SqlDataAdapter("spGetRates", conn);da.SelectCommand.CommandType = CommandType.StoredProcedure;DataSet ds = new DataSet();da.Fill(ds);grdRates.DataSource = ds.Tables[0].DefaultView;grdRates.DataBind();}protected void btnFileImport_Click(object sender, EventArgs e){// Get the filename and path from the user.Must be in UNC format or SSIS will failstring filename = Path.GetFullPath(fileSelect.PostedFile.FileName);// Update the settings table to the value from abovetry{conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InternationalWiresConnection"].ToString());cmd = new SqlCommand("UPDATE Settings SET settingValue = '" + filename + "' WHERE settingName = 'SSISRatesImportFile'", conn);conn.Open();cmd.ExecuteNonQuery();}catch (SqlException ex){// TO DO: handle exceptions}finally {if (conn != null) conn.Dispose();if (cmd != null) cmd.Dispose();}// set the name of the ssis package to runsqlAgent.SSISName = ConfigurationManager.AppSettings["ratesImportPackage"].ToString();// start the jobsqlAgent.SQL_SSISPackage();// do nothing while waiting for job to finishwhile (sqlAgent.SQL_IsJobRunning()){ }if (sqlAgent.SQL_JobSucceeded()){ lblStatus.Text = "Import Succeeded";BindRatesGrid();}else{ lblStatus.Text = "Import Failed.Please contact IT for failure details on SSIS import package."; }}}}


I assume your // TO DO: handle exceptions is the reason why the GridView does not get updated ;-)

2019年04月20日33分23秒

When I step through the code it never hits the exceptions, so I'm not sure why that would be.

2019年04月20日33分23秒

Adding some code into that section didn't make any difference.

2019年04月19日33分23秒

Seems like a good idea, but apparently FileUpload doesn't play nicely with UpdatePanel.I'm not having much luck.

2019年04月19日33分23秒