Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I found something here that say to use for for this thing..
I try to used like that:
VB
For Each ItemSelecionado In CheckMaterial.CheckedItems
    conn.Open()
    cmd.CommandText = "Update material SET `Quantidade` = `Quantidade` - 1 WHERE `Nome` = '" & CheckMaterial.CheckedItems.Item(ItemSelecionado) & "'"
    cmd.CommandType = CommandType.Text
    cmd.ExecuteNonQuery()
    conn.Close()
Next


But the program give me this error:
"The conversion of the string  "Ram 1gb [DDR]" To type ' Integer ' is not valid."


How Can I resolve that?

What I have tried:

VB
For Each ItemSelecionado In CheckMaterial.CheckedItems
    conn.Open()
    cmd.CommandText = "Update material SET `Quantidade` = `Quantidade` - 1 WHERE `Nome` = '" & CheckMaterial.CheckedItems.Item(ItemSelecionado) & "'"
    cmd.CommandType = CommandType.Text
    cmd.ExecuteNonQuery()
    conn.Close()
Next
Posted
Updated 21-Apr-18 18:49pm

1 solution

Based on the error message, it seems that the column Nome in the database is defined as integer. So you should either change the column data type or use some other (integer) property from the CheckMaterial in the condition.

Another thing is that to avoid conversion problems and SQL injections during the SQL statement execution, you should use OleDbParameter Class (System.Data.OleDb)[^] . For more information, have a look at SQL injection - Wikipedia[^]
 
Share this answer
 
Comments
Richard Deeming 24-Apr-18 10:38am    
Isn't it more likely that the Quantidade column isn't defined as a number, and the error comes from trying to subtract 1 from a string?
Wendelius 24-Apr-18 12:36pm    
Could be, but the error message

The conversion of the string "Ram 1gb [DDR]" To type...

feels more like it's related to the name, not quantity

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900