0
votes

I got 5 textboxes and one button on my Windowform , and it's display data from my access database file.

then i use update statement to update all the data key in into textbox1, textbox2, textbox3 and etc.

my update statement:

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", textbox10.text)

but it's failed with no error.

So i tried another mehod

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

and all the value i input go into textbox5. any method can i solve this?

Sorry, im new..hopefully you're understand my problem.

EDIT

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);

I put different number to different textbox, after that i preview the data, all the data value are the same...

2
according to your sql query you only update balance fielduser1659922
I display all the data from balance... how can i update multiple textbox to balance?Tham JunKai

2 Answers

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

and when you want to use them split by ,

0
votes

Try this

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);