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

Save All Rows from GridView Wpf to Sql database

3 Answers 460 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Imran
Top achievements
Rank 1
Imran asked on 04 Nov 2015, 11:37 AM
How to Save all rows from radgridview (wpf) to Sql database?

3 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 05 Nov 2015, 04:06 PM
Hello Imran,

If I understood you correctly, you want to get all the rows from a RadGridView and insert them in another database. I’m not sure how this is specifically related to RadGridView, as it is a data-bound control so you should have its source collection as part of your model. Nevertheless, here’s a simple example.

Let's assume we have a RadGridView control with x:Name="radGridView" and DataLoaded="radGridView_DataLoaded".

Then we add the following method:

private void radGridView_DataLoaded(object sender, EventArgs e)
{
    foreach (var item in radGridView.Items)
    {
        var student = item as Student;
        StudentsService.AddStudent(student);
    }
}

Assuming that our items in the GridView are students and that StudentsService.AddStudent is a method that adds the row to a remote database, we are all done.

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Imran
Top achievements
Rank 1
answered on 23 Nov 2015, 10:32 AM

Thank you for your reply..

My problem is that i am not able to save data from telerik grid to database.

e.g I have 3 columns added from text boxes to datagrid... Emid, Name, address.. I want to save all the rows at once from Telerik grid to sql database... Kindly help me if possible.

0
Dilyan Traykov
Telerik team
answered on 24 Nov 2015, 02:45 PM
Hello Imran,

RadGridView's Adding New Entries article can give you further information on the matter.
In my example, I've used Entity Framework to work with the database. You can take a look at the following tutorials on using EF with a new database and with an existing database.

Depending on when you want to send the data to the database you can use one of RadGridView's events as a trigger, for RowEditEnded, or just use a Button Click

Regards,
Dilyan Traykov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Imran
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Imran
Top achievements
Rank 1
Share this question
or