C#为一列更新多个文本框

本文关键字:更新 文本 一列 | 更新日期: 2023-09-27 18:06:06

我在Windowform上有5个文本框和一个按钮,它显示我访问数据库文件中的数据。

然后我使用update语句将所有数据密钥更新到textbox1、textbox2、textbox3等中。

我的更新声明:

cmd = new oledbcommand("UPDATE Table2 SET BALANCE = ? " + " WHERE ID = ? ", con);
cmd.parameters.addwithvalue("BALANCE", textbox5.text);
cmd.parameters.addwithvalue("BALANCE", textbox6.text);
cmd.parameters.addwithvalue("BALANCE", textbox7.text);
cmd.parameters.addwithvalue("BALANCE", textbox8.text);
cmd.parameters.addwithvalue("BALANCE", textbox9.text);

cmd.parameters.addwithvalue("ID",文本框10.text(

但它失败了,没有任何错误。

所以我尝试了另一种方法

cmd.parameters.addwithvalue("BALANCE", textbox5.text + textbox6.text + textbox7.text + textbox8.text + textbox9.text );

我输入的所有值都进入文本框5。有什么方法可以解决这个问题?

对不起,我是新来的。。希望你能理解我的问题。

编辑

I tried to cmd = new oledbcommand("UPDATE Table2 SET BALANCE = ? ", con);
    cmd.parameters.addwithvalue("BALANCE", textbox5.text);
    cmd.parameters.addwithvalue("BALANCE", textbox6.text);
    cmd.parameters.addwithvalue("BALANCE", textbox7.text);
    cmd.parameters.addwithvalue("BALANCE", textbox8.text);
    cmd.parameters.addwithvalue("BALANCE", textbox9.text);

我把不同的数字放在不同的文本框中,然后我预览数据,所有的数据值都是相同的。。。

C#为一列更新多个文本框

cmd.parameters.addwithvalue("BALANCE", textbox5.text +","+ textbox6.text  +","+ textbox7.text  +","+ textbox8.text  +","+ textbox9.text );

并且当您想要使用它们时,通过, 进行分割

试试这个

var totalBalance = Convert.ToDouble(Textbox1.Text) +  Convert.ToDouble(Textbox2.Text) + Convert.ToDouble(Textbox3.Text) + Convert.ToDouble(Textbox4.Text) +  Convert.ToDouble(Textbox5.Text) ;
cmd.parameters.addwithvalue("BALANCE", totalBalance);