Results 1 to 5 of 5

Thread: How to update database with changes made in data grid.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2013
    Posts
    25

    How to update database with changes made in data grid.

    Hello,

    I need some help with datagrid control.

    On a form I have a datagrid control and I am selecting a row from the datagrid and I have a button below which helps me perform that action on the datagrid row selected.

    Now there are basically two issues I am facing.

    1. Once I select the datagrid row and click the button, it does update the row with the necessary information but if I reload the grid, the information is still not updated in the database.
    For example, I have a column named "Status" and I have coded the datagrid to display only the records which indicate the status as "Pending". Now when I select one of the displayed rows and click the button below, it will change the status from "Pending" to "Approved". The update is also successfully displayed in the datagrid column, but the datagrid does not update the database until the form is unloaded. After I unload the form, and I go to the database and check, the status is actually updated to "Approved".
    Is there a way I can propagate the updates to the database without having to close the form???

    2. I was also in search of a solution which can help me select multiple rows from the datagrid and then click the button below which will help me approve all the selected requests at a time.
    I am currently able to select multiple rows from the datagrid but, when I click the button, it only approves the first request.

    Below is a snippet of my code for reference.

    =======================
    Code
    =======================
    Dim selected_row As String
    selected_row = grdReq.Row
    grdReq.Columns(10).Value = "Approved"
    grdReq.Columns(11).Value = "Approved by " + empname
    adodcreq.refresh
    grdreq.refresh
    =======================
    End Of code
    =======================

    Any help on this is greatly appreciated.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,484

    Re: How to update database with changes made in data grid.

    I do not use datagrid controls -- their flexibility (IMHO) is limited. I always use msFlexGrids. I might suggest you try that. It is VERY easy to do what you are proposing with a msFlexGrid (added from Components). If you DO go that route, and would like a sample on how to update a database, as well as updating the msFlexGrid based upon changes you make in the DB with other functions, let me know and I can send one. Of course, this forum has many examples as well.

    If you stay with a datagrid control, you possibly need to loop through your selected rows to update each one.

  3. #3
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,346

    Re: How to update database with changes made in data grid.

    You have to loop through the rows and update the ones that are selected 1 at a time. You can't do them all at once

    The fact that you are working with SelectedRow should be a hint that it is only 1 row rather than SelectedRows

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2013
    Posts
    25

    Re: How to update database with changes made in data grid.

    Hello,

    Thanks for your replies.

    Sam,

    Could you please illustrate the use of MSFlexGrids as per my request.

    I am using FlexGrids in the application but not for this purpose.
    Please provide me an example of how I use an MSFlexGrid to perform operation on data in it using a button click.

    Thank you in advance.

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,484

    Re: How to update database with changes made in data grid.

    Look at the cmdPopGrid2 command button's click event in this example....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width