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

Database and RadGridView connection

4 Answers 145 Views
GridView
This is a migrated thread and some comments may be shown as answers.
shahar
Top achievements
Rank 1
shahar asked on 25 Mar 2011, 09:57 AM
Hi,

I've created a GridView control in my application and I want it to be connected to my SQL database (i mean to sync between the two)
That way the GUI application will be the interface of the DB, so the user won't be needed to open the DB with SQL Server Management.

My DB attached in image "1.jpg", and my application in image "2.jpg".
What is the easy way to connect between the two?
I want to do that when I change (insert/update/delete) any row in the gridview, and click "Save" - DB will be updated.
and when I open the application it will select from it.

What is the easiest way to sync it in RadGridView?

Thanks!

4 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 10:10 AM
Hello Shahar,

There are so many ways to do this, you could use entity framework, or just follow this simple tutorial to connect to a database table.

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

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Richard Slade
Top achievements
Rank 2
answered on 25 Mar 2011, 10:26 AM
Hello,

In addition to Emanuel's suggestions I would strongly advise having a look at Telerik's own Open Access ORM. This makes data access really simple, you can forward and reverse map your database to classes in a couple of clicks and all of your data access can be done without even touching your database.

The Open Access Product Page can be found here

I hope that helps but let me know if you need more information
Richard
0
shahar
Top achievements
Rank 1
answered on 25 Mar 2011, 01:40 PM
Hi Emanuel Varga,

Your answer was great, thank you.
I have another question please.
I want to implement "Add" and "Delete" row actions.
When I use columns that don't allow empty (null) values, I can't use the line:
tableRadGridView.Rows.Add("")
because it will throw an exception.

What should I do to add an empty line to the grid using a button? and what should I do you delete the selected row also using a button?

Thanks!
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 25 Mar 2011, 02:28 PM
Hello again shahar,

But why do you need a button for add? You can just use the new row to enter data and just press enter to commit changes.
For delete, you can just do the following:
private void radButton1_Click(object sender, EventArgs e)
{
    if (radGridView1.CurrentRow != null)
    {
        radGridView1.Rows.Remove(radGridView1.CurrentRow);
    }
}

After this you should call an update on the dataset / entity.

I also would suggest using row or cell validation to prevent the user from trying to add rows without all the required values.

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

Best Regards,
Emanuel Varga
Telerik WinForms MVP
Tags
GridView
Asked by
shahar
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
shahar
Top achievements
Rank 1
Share this question
or