D
D
deadspace122022-04-04 08:27:47
MySQL
deadspace12, 2022-04-04 08:27:47

How to update a specific row of a db table in a dataGridView?

I displayed my query in the datagridview element, where my table with the MySQL database is displayed.
I'm trying to make it so that when I click on any row in the datagridview, it will automatically enter the value in the column with an Update query.
here is my code:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            string CommandText;
            Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);
            for (int i = 0; i < selectedRowCount; i++)
            {
                    CommandText = "UPDATE `auto`.`transportation` SET `active` = 'X' WHERE(`idtransportation` = '" + dataGridView1.Rows[i].ToString() + "');";
                    My_Execute_Non_Query(CommandText);
                    button1_Click(sender, e);
            }
        }

and I get this error:
MySql.Data.MySqlClient.MySqlException: "Truncated incorrect DOUBLE value: 'DataGridViewRow { Index=0 }'"
please advise me how to solve the problem. Thanks in advance!!!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nekit Medvedev, 2022-04-04
@NIKROTOS

Is id equal to table row?
You need a specific table cell.
dataGridView1.Rows[i].Cells[0].Value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question