Web App - Datagrid - Refreshing

Posted on 2004-11-08
Last Modified: 2010-04-24

      I have a datagrid on a form with controls to allow the adding of a new record to the database.  The adding process works fine, except that after I click the Save button, the grid doesn't reflect the new item (if it's on the same page currently shown) unless I flip pages in the datagrid away from and back to that page.  I want to make the grid automatically update itself to show the new record.  Here's my code:


        DBGrid1.DataSource = DS_UserSetup1

     So once the new record is saved to the database, then the dataset is told to accept the changes.  Afterwards, I refill the dataset, reset the datasource for the grid and tell it to bind again.  But this apparently doesn't make the control refresh.  I still have to flip to the next page and then back in the datagrid to see the new record.

Question by:gleznov
    LVL 11

    Expert Comment

    Is the Dataadapter configured to update the Dataset that he is updateing?

    Well if you made the DA with a wizzard there is a checkbox that will return the current inserted/Updated row in case you update/Insert data?

    Can you post the SQL That the DA is using for the Update?

    Author Comment

    I'm not sure exactly what you're wanting - I used the drag-n-drop dataadapter, used the SQL statement mode, if I hit advanced options all three are checked, and if you want the text under properties in the UpdateCommand area, let me know.

    LVL 11

    Expert Comment

    Yes that text please :)

    After reading my own response i must admit it sounds horrible :)
    LVL 2

    Accepted Solution

    'after entering the record clear the datset
    then make a new instance
    DS_UserSetup1=new dataset()
    and then fill the data and bind it to the datagrid
    LVL 10

    Expert Comment

    U have to use the Update method of the DataAdapter.

     Dim myConn As New OleDbConnection(myConnection)
        Dim myDataAdapter As New OleDbDataAdapter()
        myDataAdapter.SelectCommand = New OleDbCommand(mySelectQuery, myConn)
        Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)


        Dim custDS As DataSet = New DataSet

        ' Code to modify data in DataSet here

        ' Without the OleDbCommandBuilder this line would fail.


        CreateCmdsAndUpdate = custDS

    Once u do this u can check whether the dataset has accepted the changes. Then u can use the
    datagrid.Datasource = custDS.

    U have to do all this within
    if Not Page.IsPostback

    End if

    Author Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    This video discusses moving either the default database or any database to a new volume.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now