A
A
Andrey Fomin2021-01-08 15:03:41
SQLite
Andrey Fomin, 2021-01-08 15:03:41

How to submit a request?

Hello!
There is such a form for making transfers to other users.
And when you click on the "Perform translation" button, according to the original idea, the corresponding value is taken from the table and updated, but there is a moment that was written not quite right.
The CashAmount column is of type INTEGER if so
Here is the table:
5ff847a5d8924777538681.png
Here is the button processing:

SQLiteConnection Transfer = new SQLiteConnection("Data source = accounts.db");
            Transfer.Open();
            try
            {
                SQLiteCommand cmd = new SQLiteCommand($"UPDATE users SET CashAmount = 'CashAmount + {textBox2.Text}' WHERE Login = '{LoginField.Text}'", Transfer);
                cmd.ExecuteNonQuery();
            }
            finally
            {
                MessageBox.Show($"Операция выполнена успешно!");
                Transfer.Close();
            }

And the question is: How to remake the query so that the value from the base is considered as a number, and also so that not 40000 + 500, but 40500, but 40500 is written to the cell?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vilinyh, 2021-01-08
@a63826ndrew

If you omit a bunch of subtleties about SQL injection and data validation, then just change

SQLiteCommand cmd = new SQLiteCommand($"UPDATE users SET CashAmount = 'CashAmount + {textBox2.Text}' WHERE Login = '{LoginField.Text}'", Transfer);

on the
SQLiteCommand cmd = new SQLiteCommand($"UPDATE users SET CashAmount = CashAmount + '{textBox2.Text}' WHERE Login = '{LoginField.Text}'", Transfer);

PS: the CashAmount column has a string type for you, not an integer type, judging by what was saved there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question