Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Web App - Datagrid - Refreshing

Hi,

      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:


            DS_UserSetup1.AcceptChanges()

        SqlDataAdapter1.Fill(DS_UserSetup1)
        DBGrid1.DataSource = DS_UserSetup1
        DBGrid1.DataBind()

     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.

JP
0
gleznov
Asked:
gleznov
1 Solution
 
rdrunnerCommented:
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?
0
 
gleznovAuthor Commented:
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.

JP
0
 
rdrunnerCommented:
Yes that text please :)

After reading my own response i must admit it sounds horrible :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ahmadfuwadCommented:
'after entering the record clear the datset
DS_UserSetup1.clear()
then make a new instance
DS_UserSetup1=new dataset()
and then fill the data and bind it to the datagrid
0
 
123654789987Commented:
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)

    myConn.Open()

    Dim custDS As DataSet = New DataSet
    myDataAdapter.Fill(custDS)

    ' Code to modify data in DataSet here

    ' Without the OleDbCommandBuilder this line would fail.
    myDataAdapter.Update(custDS)

    myConn.Close()

    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
0
 
gleznovAuthor Commented:
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now