I'm using Visual Studio c# (spanish)

The code:

cmd.CommandText = "UPDATE cursos SET saldo = saldo - '" + cantidad.ToString() + "' where id = '" + vID + "' ";

vID is a string variable.

The problem is here:

Don't work where id = '" + vID + "' neither where id = '" + vID.ToString() + "'

The error:
(Translating) Don't match data type in criteria expression

saldo working OK.

Can you help me?. Thx.

You are trying to do math with a string saldo = saldo - '" + cantidad.ToString() + "' . If cantidad is a number, then you want saldo = saldo - " + cantidad ... . Leave out the single quotes (') around cantidad.

Thx but the problem is not in SALDO. This work fine. The problem is in WHERE ID =

Use parameterized query to avoid datatype mismatch.

cmd.CommandText = "UPDATE cursos SET saldo = saldo - @cantidad where [id] = @id";
cmd.Parameters.AddWithValue("@cantidad",cantidad);
cmd.Parameters.AddWithValue("@id",vID);

thx adatapost!! Solved with parameters. Working fine.

You're welcome!

I'm glad you got it working. Please mark this thread as solved if you have found an answer to your question and good luck!