Save All Rows from GridView Wpf to Sql database

4 posts, 0 answers
  1. Imran
    Imran avatar
    2 posts
    Member since:
    Oct 2012

    Posted 04 Nov 2015 Link to this post

    How to Save all rows from radgridview (wpf) to Sql database?
  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 05 Nov 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Imran
    Imran avatar
    2 posts
    Member since:
    Oct 2012

    Posted 23 Nov 2015 Link to this post

    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.

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 24 Nov 2015 Link to this post

    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 example 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
Back to Top