This is a migrated thread and some comments may be shown as answers.

Insert / Update Records

19 Answers 762 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shanghai360
Top achievements
Rank 2
Shanghai360 asked on 08 Jan 2009, 02:50 AM
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!

19 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 09 Jan 2009, 04:27 PM
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.
0
Shanghai360
Top achievements
Rank 2
answered on 09 Jan 2009, 08:18 PM
Nick,

Thank you for the guidance!  I appreciate it.

0
Fernando
Top achievements
Rank 1
answered on 24 Jan 2009, 12:40 AM
I have the same problem, how did you solve this issue

Thanks in advance.
0
Mike
Telerik team
answered on 26 Jan 2009, 07:16 AM
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.
0
Adam El Shafie
Top achievements
Rank 1
answered on 14 Oct 2009, 09:56 AM
Hello, I have the same problem
I can edit, insert into the radgrid but without change in my datasource

please help!!!!!!!

0
Nikolay
Telerik team
answered on 16 Oct 2009, 03:25 PM
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.
0
Chad Hensley
Top achievements
Rank 1
answered on 17 Apr 2010, 11:21 PM
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


0
Meena Godavari
Top achievements
Rank 1
answered on 11 May 2010, 03:05 PM

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.

 

0
SachinC
Top achievements
Rank 1
answered on 06 Oct 2010, 02:46 PM
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.

0
Emanuel Varga
Top achievements
Rank 1
answered on 06 Oct 2010, 04:04 PM
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
0
SachinC
Top achievements
Rank 1
answered on 06 Oct 2010, 04:53 PM
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.
0
Emanuel Varga
Top achievements
Rank 1
answered on 06 Oct 2010, 05:09 PM
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
0
SachinC
Top achievements
Rank 1
answered on 06 Oct 2010, 05:33 PM
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

0
Emanuel Varga
Top achievements
Rank 1
answered on 06 Oct 2010, 06:14 PM
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
0
Paul Patterson
Top achievements
Rank 1
answered on 07 Oct 2010, 05:46 PM
@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?





0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Oct 2010, 05:58 PM
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
0
Paul Patterson
Top achievements
Rank 1
answered on 07 Oct 2010, 06:16 PM
Ah. Gotcha, thanks for the quick reponse.

Cheers.
0
Scott
Top achievements
Rank 1
answered on 27 Apr 2017, 04:53 PM

I know this is an old post, but I ran into this problem and it turns out is was a dbContext error on my part.

I was implementing the following code to create the radGridView datasource.

        private void radDateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            MOSES_Entities dbNow = new MOSES_Entities();
            var invoices = dbNow.t_ClientInvoices.Select(p => p);
            this.t_ClientInvoicesbindingSource.DataSource = invoices.ToList();
            ClientInvoicesradGridView.DataSource = t_ClientInvoicesbindingSource;
        }

As soon as I referenced a dbContext that was scoped to the entire form, my problem went away.

Hope this helps someone in the future.

-Scott

0
Hristo
Telerik team
answered on 28 Apr 2017, 11:45 AM
Hello Scott,

Thank you for writing in the thread. I am sure that it will be helpful to our community.

Please let me know if you have further questions.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Shanghai360
Top achievements
Rank 2
Answers by
Nick
Telerik team
Shanghai360
Top achievements
Rank 2
Fernando
Top achievements
Rank 1
Mike
Telerik team
Adam El Shafie
Top achievements
Rank 1
Nikolay
Telerik team
Chad Hensley
Top achievements
Rank 1
Meena Godavari
Top achievements
Rank 1
SachinC
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Paul Patterson
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or