Answer the question
In order to leave comments, you need to log in
How to generate sql query from datagridview c#?
How to teach DGV to form the query I need? That is, there is 1 DGV row, for example, 2 variables (if there are 2 columns) there is a pre-prepared sql query in which key data is missing, and this data is obtained from the DGV row.
It comes out something like this:
INSERT INTO cli (name, phone) values('ЗНАЧЕНИЕ ИЗ СТОЛБЦА 1', 'ЗНАЧЕНИЕ ИЗ СТОЛБЦА 2')
Answer the question
In order to leave comments, you need to log in
> How to teach DGV to form the query I need?
The grid itself does not know how to form anything.
There is nothing like this in .NET, THAT high-level.
You need to get the selected grid row yourself, then the values from its cells, and finally compose the SQL query.
Moreover, the selected row can be either dataGridView1.CurrentRow or dataGridView1.SelectedRows (depending on where exactly the user clicks), so you need to implement both options, with checks for null.
Variant with dataGridView1.CurrentRow:
Variant with dataGridView1.SelectedRows:
MessageBox.Show(dataGridView1.SelectedRows[0].Cells[0].Value.ToString()); // Cells[0] - первый столбец
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question