A
A
Artyom2015-04-16 14:13:09
PostgreSQL
Artyom, 2015-04-16 14:13:09

C# - PostgreSQL How to work with GridView?

There is a database on postgres, in which there are several different tables. There is a program on sharp, which in the future should work with this database and "change, delete and add" data to tables. All tables are loaded into the DataGridView. A combobox hangs and a table is selected from the list in it.
Now the question is, how can I write a more or less universal way to add, delete and change data in a table? I somehow did the deletion clumsily on the selected line and the value of the first column (id), but what about the insert and change? Each table has a different number of columns and their names. I thought about trying to implement it through DataAdapter.Update, but I did not understand by what principle the commands for several changed fields are written there.
Those. ideally, having selected any table from the list, we edit it directly in the DataGridView, press the "Save" button and all queries are entered into our database. To implement manually all this for each table is some kind of dubious exercise, maybe there is some way?
I know how to form an sql-query with parameters from a regular textbox. But for different tables there will be crutches from switches.
Or what is the best way to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-04-16
@Artem_007

You need to decide on a number of requirements for your application, in particular, at what level of abstraction it works with the database. If at the meta level - i.e. for your program there is nothing but a set of some tables and views in the database (in other words, you have something like a standard shell for working with the database) - then this is one situation, and here you would work with INFORMATION_SCHEMA (so without switches) and really collect SQL- requests yourself. If you have standard business tasks (create a record about a customer, order, ..., save, edit data), and you specifically know what kind of tables you have and what is stored there, then read about the current approaches to working with data in databases using ORM, in the case of dotnet - Entity Framework and NHibernate .

V
Vladimir S, 2015-04-16
@hePPer

try to implement a repository and work with it, and not directly with tables from the database.
there is an example here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question