Updating Records in a Database by Editing and Updating a GridView

Discussion in 'Databases' started by luke_jack61188, Jul 9, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello,


    I'm trying to build editing facilities into a gridview so that when the data in the gridview is changed and the "Update" button is clicked, the changes are committed to the database. I have a datagrid displaying customer feedback and need to be able to update a field called "Dealt_With" which determines whether the feedback has been acted on or not. I've selected the data and displayed it in a grid view and I'm trying to use the following as an UPDATE statement:


    UPDATE Feedback SET Dealt_With=@DealtWith WHERE Order_Number = @Order_Number


    I've tried using a command field column but without success. Ideally, I'd just like to display a dropdown list with options for "Yes" and "No" (which I've already got) and then have an Update button which the user can click to commit the changed Dealt_With status to the database.


    I'd be really grateful if anyone could help me on this one becuase I'm really struggling with it.


    Cheers,


    Luke
     
  2. wwv

    wwv

    I am using an Edit command field in a data grid and the </o:p>
    RowEditing event to update the rows.</o:p>
    </o:p>
    The same using a Select command field and the SelectedIndexChanged event.</o:p>
    </o:p>
    The both work fine.</o:p>
    </o:p>
    Valentin</o:p>
    MCP C#</o:p>
    Do not hesitate to contact me!</o:p>
    www.wwv-it.eu </o:p>[email protected]
     
  3. The best way to use datagrids and gridview is to have them binded to a data source, whether it be an object data source, or sql data source, etc... I prefer the object data source because the code is seperate.

    Drag the datasource from the toolbar to the page, and set its select, update, insert operations etc. Have your datagrid's/gridview's datasourceID = the datasource's ID. When you click update, edit, etc. the datasource will handle the updating, editing, deleting etc. and then refresh the data. For a yes/no field, the best thing to do is use a checkbox column. The gridview will automatically bind this data to the datasource.

    -Dan
     
  4. Hi Dan,

    Thanks very much for your email. What I need to know now is what my INSERT, UPDATE and DELETE statements should be so that any changes that are made to the GridView are implemented on the actual database.

    Could you please let me know what my SQL statements should look like?

    Again, thanks very much I really appreciate your help.

    Cheers,
    Luke
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page