Datagrid after SQL update

Missy

New Member
After I update my database, the datagrid still shows the previous value when I rebind the data after the OnUpdateCommand is fired. If I press the refresh button (which reposts), then the new value shows up fine.<BR><BR>Public Sub FillDataGrid()<BR>'Set up connection<BR>Dim objConn As New OleDbConnection<BR>"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inetpubwwwrootchartchart.mdb")<BR><BR>'Open Connection<BR>Dim objCmd As New OLEDbDataAdapter("Select * FROM labs", objConn)<BR><BR>'Fill Dataset<BR>Dim ds As DataSet = new DataSet()<BR>objCmd.Fill(ds, "labs")<BR><BR>Labs.DataSource = ds.Tables("labs").DefaultView<BR>Labs.DataBind()<BR>End Sub<BR><BR>Sub Labs_Update(Sender as Object, E as DataGridCommandEventArgs)<BR>'Grab values<BR>'Open database and execute sql statement<BR>objConn.Open()<BR>objCmd.ExecuteNonQuery()<BR>Labs.EditItemIndex = -1<BR>FillDataGrid()<BR>End Sub<BR><BR>Is there something I am doing wrong?<BR>Other than not closing your connections? ;) Other than that it looks ok to me. If you hit update again will it show the changes from before, or the original data?Yes, other than not closing my connections. :)<BR><BR>When I click the "edit" link, the row converts to textboxes.<BR>I change a few values and click the "update" link.<BR>The form posts back but the values have not changed.<BR><BR>However... if I click the Refresh button or some other link that causes a postback I can see the updated values. Here is the code:<BR><BR>Sub Page_Load(Sender as Object, E as EventArgs)<BR> If NOT Page.IsPostBack Then<BR> FillDataGrid()<BR> End If<BR>End Sub<BR><BR>Public Sub FillDataGrid()<BR> 'Set up connection<BR> Dim objConn As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inetpubwwwrootchartchart.mdb")<BR><BR> 'Open Connection<BR> Dim objCmd As New OLEDbDataAdapter("Select * FROM labs", objConn)<BR><BR> 'Fill Dataset<BR> Dim ds As DataSet = new DataSet()<BR> objCmd.Fill(ds, "labs")<BR><BR> objConn.Close()<BR><BR> Labs.DataSource = ds.Tables("labs").DefaultView<BR> Labs.DataBind()<BR>End Sub<BR><BR>Sub Labs_Edit(Sender as Object, E as DataGridCommandEventArgs)<BR> Labs.EditItemIndex = E.Item.ItemIndex<BR> FillDataGrid()<BR>End Sub<BR><BR>Sub Labs_Cancel(Sender as Object, E as DataGridCommandEventArgs)<BR> Labs.EditItemIndex = -1<BR> FillDataGrid()<BR>End Sub<BR><BR>Sub Labs_Update(Sender as Object, E as DataGridCommandEventArgs)<BR> If Page.IsValid Then<BR> Dim txtID As String = E.Item.Cells(0).Text<BR> Dim txtFC As TextBox = E.Item.Cells(3).Controls(1)<BR> Dim txtTC As TextBox = E.Item.Cells(4).Controls(1)<BR> Dim txtACD As TextBox = E.Item.Cells(5).Controls(1)<BR><BR> Dim strSQL As String = "UPDATE labs SET NumFinished=" & txtFC.Text & ", NumComputers=" & txtTC.Text & ", ApproxCompletionDate=#" & txtACD.Text & "# WHERE ID = " & txtID<BR> 'Response.Write(strSQL)<BR><BR> Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inetpubwwwrootchartchart.mdb")<BR> Dim objCmd As New OLEDbCommand(strSQL, objConn)<BR> objConn.Open()<BR> objCmd.ExecuteNonQuery()<BR><BR> objConn.Close() <BR><BR> Labs.EditItemIndex = -1<BR> FillDataGrid()<BR> End If<BR>End Sub<BR>I don't see anything wrong with that code, I wonder if the access database is not reflecting the changes fast enough. Try calling FillDataGrid() twice at the end of the Labs_Update sub and see what it does.Thanks, that worked! I don't see anything wrong with the code either, but I'd really like to figure out what is causing the problem. I'd rather not have to fill the datagrid twice for any SQL updates I need to make. :(It looks like Access is not reflecting the changes fast enough, since doing it twice worked fine. You could try creating a pause in the code, but I am not sure how to do that.
 
Back
Top