如何让程序从checklistbox中选择不同的选定项并更新一个mysql列? [英] How can I make the program select different selected items from a checklistbox and update one mysql column?

查看:91
本文介绍了如何让程序从checklistbox中选择不同的选定项并更新一个mysql列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找到了一些可以用于此事的东西..

我尝试使用这样的东西:

Hi, I found something here that say to use for for this thing..
I try to used like that:

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:

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

推荐答案

根据错误消息,数据库中的 Nome 列似乎被定义为整数。因此,您应该更改列数据类型或在条件中使用CheckMaterial中的其他(整数)属性。



另一件事是避免转换问题和SQL在SQL语句执行期间进行注入,您应该使用 OleDbParameter类(System.Data.OleDb) [ ^ ]。有关更多信息,请查看 SQL注入 - 维基百科 [ ^ ]
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[^]


这篇关于如何让程序从checklistbox中选择不同的选定项并更新一个mysql列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆