P
P
Pavel2019-07-09 15:52:57
C++ / C#
Pavel, 2019-07-09 15:52:57

How to delete and add rows to the database?

I want to delete and add rows to the database izi datagridview on button click. I made an addition similar to Mssql:

adap.UpdateCommand = cd.GetInsertCommand();
adap.Update(table);
dataGridView1.DataSource = table;

But when writing code to delete a line
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                dataGridView1.Rows.Remove(row);
            }
            adap.UpdateCommand = cd.GetDeleteCommand();
            adap.Update(table);
            dataGridView1.DataSource = table;

Gives an error message:
Dynamic SQL generation for an UpdateCommand is not supported for a SelectCommand that does not return any key column information

Tell me how to delete the line completely. Already tried everything. Also, adding only after entering the second time is added, but I'll figure it out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wundarshular, 2019-07-18
@Wundarshular

DataGridView, despite its relatively rich functionality, is only an element for displaying data from a source. That is, you do not need to operate on strings in the dgv itself. Instead, work with the data source it is bound to: the bindingSource or the table itself in your DataSet.
That is, all the actions that you visually perform in the dgv must be performed on the data source.
In addition, I remind you that in order to record changes on the server, you will need to synchronize your DataSet with the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question