简体   繁体   中英

Update sql-command string from c# ExecuteNonQuery();

App works but UPDATE through WPF does not work

string sqlIns = "UPDATE Team_table SET result1 = '4:2' where name1=@Team1 and name2=@Team1";    
string Team1_string = Team1.Text;

// Team1, Team2, result1, result2 is the name of TextBox controls

cmdIns.Parameters.AddWithValue("@Team1", Team1_string);
string Team2_string = Team2.Text;
cmdIns.Parameters.AddWithValue("@Team2", Team2_string);
string result1_string = Result1.Text;
cmdIns.Parameters.AddWithValue("@result1", result1_string);

How to do it work?

Unless you are updating the rows when teams play themselves the error is from:

name1=@Team1 and name2=@Team1

I am fairly cofident you ment for that to be

name1=@Team1 and name2=@Team2

You are not setting connection string to SqlConnection Object properly

Replace this :

SqlConnection con = new SqlConnection(TTKZS);

with following :

 SqlConnection con = new SqlConnection(hhconn);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM