Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create editor for database view (with joins) in Windows Forms/WPF?

Tags:

c#

sql

winforms

What would be the simplest way to create a quick editor for some data in the database in WPF/WinForms, where the data is represented by a View in the SQL Server database?

Say I have a table Person { id int, name nvarchar(max), GenderID int, CityID int}, where GenderID and CityID is a reference into tables Gender and City. In the editor, the Person would appear as textbox for name, combobox for gender (selecting names of the genders from Gender table) and the same for the city column.

Is there something easy that I can do so some control/code would generate this? If I'd like to only select data, then WinForms DataGridView or WPF DataGrid can generate a column for each property, and show a row for each object in a collection. -

Is there some kind of similar magic control, that could do this for a database view, if the relations are defined by a foreign key?

It seems to me that thousands of developers have faced this kind of problem - to quickly create a GUI for editing database rows with relationships to other tables, so there should be some kind of universally accepted solution. Or is everyone doing this in the code? Or, if there is a tool for this in other language, not C#, not Windows Forms - like dBase.

like image 459
Axarydax Avatar asked May 14 '12 09:05

Axarydax


1 Answers

You are describing what is known as scaffolding in web development. Scaffolding is a way to automatically generate UIs for each table in the database. Scaffolding lets you create a functional UI for viewing and editing data based on the schema of the data. Here are a couple of resources for WPF scaffolding.

  1. There is a WPF scaffolding article on the Code Project website: WPF CRUD Generator (Scaffolding)
  2. There is also a Codeplex project that could be helpful: WPF Scaffolder

Enjoy!

like image 132
Tarzan Avatar answered Sep 30 '22 13:09

Tarzan