Insert / Update Records

18 posts, 0 answers
  1. Shanghai360
    Shanghai360 avatar
    3 posts
    Member since:
    Oct 2008

    Posted 07 Jan 2009 Link to this post

    I'm new to winforms and telerik controls but I'm almost embarressed to write this. 

    I'm using a GridView control in a basic winform application (.net 3.5) .  I'm using a  sql server database table datasource.    I set the gridview to AllowAddNewRow and AllowEditRow.  Very easily setup the app to view the data.  I'm able to insert and update records in the grid.  But those insert/updates are not committed to the database. 

    I would appreciate any direction to help me learn how to simply add/update/delete records via the gridview.

    Thanks!
  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 09 Jan 2009 Link to this post

    Hello Shanghai360,

    Thank you for your question.

    In general, you may find more resources in our documentation which can be accessed online. In particular, RadGridView does not have internal data structures but uses its datasource object. Therefore, whatever is displayed in the RadGridView in bound mode is the content of your datasource. The reverse is also true. If you change the data in your data source object the UI is notified about the change and refreshes the cells content. In your case, this is probably a typed DataSet automatically generated by Visual Studio for your data base. If so, the data should be persisted. Please check the documentation for your DataSource in msdn. Perhaps you need to call an Update on your data base adaptor if you are using the disconnected data base model. Depending n your requirements you should choose the most suitable event on which you should call Update. For example:
    - RadGridView.CellEndEdit - this executes after each cell is edited
    - BindingSource.ListChanged
    - Save button click, etc

    If you want to edit your data programmatically outside the grid (e.g. adding row using a button on your form), my general tip is to use your DataSet, BindingList, etc API when you handle your purely data base operations and RadGridView API when your data source API cannot be used. Most of the time you will not need the second approach at all, because the RadGridView will handle presentation automatically.

    Do not hesitate to write me back if you have more questions. Sending us a sample project or a code snippet can be very useful when answering your questions and reproducing the issues that you have encountered.

    Regards,
    Nick
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Shanghai360
    Shanghai360 avatar
    3 posts
    Member since:
    Oct 2008

    Posted 09 Jan 2009 Link to this post

    Nick,

    Thank you for the guidance!  I appreciate it.

  5. Fernando
    Fernando avatar
    2 posts
    Member since:
    Dec 2008

    Posted 23 Jan 2009 Link to this post

    I have the same problem, how did you solve this issue

    Thanks in advance.
  6. Mike
    Admin
    Mike avatar
    640 posts

    Posted 26 Jan 2009 Link to this post

    Hello Fernando,
    In general, you may find more resources in our documentation which can be accessed online. In particular, RadGridView does not have internal data structures but uses its datasource object. Therefore, whatever is displayed in the RadGridView in bound mode is the content of your datasource. The reverse is also true. If you change the data in your data source object the UI is notified about the change and refreshes the cells content. In your case, this is probably a typed DataSet automatically generated by Visual Studio for your data base. If so, the data should be persisted. Please check the documentation for your DataSource in msdn. Perhaps you need to call an Update on your data base adaptor if you are using the disconnected data base model. Depending n your requirements you should choose the most suitable event on which you should call Update. For example:
    - RadGridView.CellEndEdit - this executes after each cell is edited
    - BindingSource.ListChanged
    - Save button click, etc

    If you want to edit your data programmatically outside the grid (e.g. adding row using a button on your form), my general tip is to use your DataSet, BindingList, etc API when you handle your purely data base operations and RadGridView API when your data source API cannot be used. Most of the time you will not need the second approach at all, because the RadGridView will handle presentation automatically.

    Do not hesitate to write me back if you have more questions. Sending us a sample project or a code snippet can be very useful when answering your questions and reproducing the issues that you have encountered.


    Regards,
    Mike
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  7. Adam El Shafie
    Adam El Shafie avatar
    7 posts
    Member since:
    Feb 2007

    Posted 14 Oct 2009 Link to this post

    Hello, I have the same problem
    I can edit, insert into the radgrid but without change in my datasource

    please help!!!!!!!

  8. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 16 Oct 2009 Link to this post

    Hello Adam El Shafie,

    I suggest that you read the responses of my colleagues Nick and Mike. The answer to your question is most probably given there.
     
    If you can't find the answer for your particular scenario, we will need detailed description of your databinding approach. It will be best if you open a new support ticket and send us a sample project. This will allow us to help you further.

    Greetings,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Chad Hensley
    Chad Hensley avatar
    54 posts
    Member since:
    Feb 2005

    Posted 17 Apr 2010 Link to this post

    I think the problem could be occurring because some are using the SQL CE database and the database changes are not saved from build to build.

    I answered that question here.

    http://social.msdn.microsoft.com/Forums/en/sqlce/thread/a4bae5d5-f8bb-44a9-921c-ea817193ae01


  10. Meena Godavari
    Meena Godavari avatar
    1 posts
    Member since:
    Apr 2009

    Posted 11 May 2010 Link to this post

    In the RadGridView_RowsChanged event add the code
    this.TableAdapter.Update(this.Dataset.Table) which takes care of the update.
    Use e.Action to trap Insert/Delete/Update and code accordingly.

     

  11. SachinC
    SachinC avatar
    23 posts
    Member since:
    Sep 2010

    Posted 06 Oct 2010 Link to this post

    Hello,

    i am new to telerik controls and windows application.
    can any body tell me how to update the database after updateing the hierarchical grid (parent and child row).
    which event should i use to get the cell values for both parent and child row and update the database.

    please suggest.

    thanks in advance.

  12. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 Oct 2010 Link to this post

    Hello Sachin,

    Did you check the answer posted above your question, or the other pointers that Mike provided?
    Those points should help you do what you want,

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  13. SachinC
    SachinC avatar
    23 posts
    Member since:
    Sep 2010

    Posted 06 Oct 2010 Link to this post

    Hello Emanuel,

    Thanks for reply.

    i didnt get the above post.

    which event should i use to update the database.
    i am ushig heararchy grid.
    and i need to update both Parent element as well as child element.

    Thanks.
  14. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 Oct 2010 Link to this post

    Hello again Sachin,

    I understand what you want to do here, but because you are using a DataSet, and I'm guessing that you are defining relations inside your grid ( or you already have relations defined ), because of this, the changes you are making on the grid, are applied onto the underlining data source, the data set.

    After that you can use one of the available documents, in order to find out how to update your data as a base reference you could check out this article Updating Data Sources with DataAdapters (ADO.NET), and as for the event on which you should update the data into the db you have a few options:
    - RadGridView.CellEndEdit - this executes after each cell is edited
    - RadGridView.RowsChanged
    - Save button click, etc

    Because this is a general .Net question, you should be able to find a lot of answers and solutions on the web on how to Get / Update data.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  15. SachinC
    SachinC avatar
    23 posts
    Member since:
    Sep 2010

    Posted 06 Oct 2010 Link to this post

    Hello again Emanuel,

    Thanks for reply.

    1. when i edit the child cell and press tab/ enter / click or next cell, the cell value doesnt update.
    2. as you told i used both but no success, which event should i used?

    i am ushig heararchy grid.
    i have given relation programatically.

     

     

    i have given list object as a datasource to grid

    i am using Entity Framwork to interact with database.

    my condition is i update parent row cell it must update parent cell
    and if i update child cell  it must update child.

    but i am having 4 four columns i need to update only once.
    by cellEndEdit it will update 4 times

    Please suggest.

    Thanks

  16. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 06 Oct 2010 Link to this post

    Hello Sachin,

    In my experience people often change they're mind, so because of this i try, as much as possible to show a Save and Cancel button on the form.
    There are a few advantages of doing so, like:
    First, you won't call the database excessively, second if you always update the data in the DB what happens when the user makes a mistake? another update if you have some old cached data stored somewhere?
    Second, you could easily create an internal list of changed Items (parents + children) and when the user calls a save it will save just the items contained in that list.

    If you don't like, or don't agree with this approach, you could do something else, like saving on control leave, so at least like that you will always perform a save when that user "apparently finished" working on that grid.

    Best Regards,
    Emanuel Varga
  17. Paul Patterson
    Paul Patterson avatar
    40 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    @Emanuel Varga

    I don't believe you understood what Sachin (not Sachi"m") was asking.

    He has a RadGrid that is programatically bound to IQueryable types from an Entity Framework context. There is a parent child hierarchy occurring, in which the relationships are also created via code. 

    Editing the top level, or Master Template, is fine, however when he makes an edit to a template used in the hierarchy, the value does not change in the grid. It remains the same.

    It appears that the issue may be one of updating the underlying databinding. How can one update the row's data element?





  18. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    Hello Paul,

    First i want to apologize to Sachin, for the misspelling, sorry it was really a mistake :(.

    Second, I was trying to ask him to try handling the CellEndEdit event this on this other  thread he created on this issue, please join us there.

    Best Regards,
    Emanuel Varga
  19. Paul Patterson
    Paul Patterson avatar
    40 posts
    Member since:
    May 2010

    Posted 07 Oct 2010 Link to this post

    Ah. Gotcha, thanks for the quick reponse.

    Cheers.
Back to Top
UI for WinForms is Visual Studio 2017 Ready