Home > database > When the field is a variable, how to update its value?
When the field is a variable, how to update its value?
Time:11-21
I want to find called nowlevel fields and update its numerical, nowlevel is a variable, how to do? Public void savetDatalevelstars (int id, string nowlevel, int starsnum) { String connStr="Database=angrybird; The datasource=127.0.0.1; Port=3306; User=root; The PWD=root; "; Conn=new MySqlConnection (connStr); conn.Open(); MySqlCommand CMD=new MySqlCommand (" update scores set nowlevel='" + @ nowlevel + "' where userid='" + id + "' ", conn); CMD. The Parameters. AddWithValue (" stars, "starsnum); CMD. ExecuteNonQuery (); Conn. Close (); }
CodePudding user response:
Public void savetDatalevelstars (int id, string nowlevel, int starsnum) {
nowlevel="Test"; String connStr="Database=angrybird; The datasource=127.0.0.1; Port=3306; User=root; The PWD=root; "; Conn=new MySqlConnection (connStr); conn.Open(); MySqlCommand CMD=new MySqlCommand (" update scores set nowlevel='" + @ nowlevel + "' where userid='" + id + "' ", conn); CMD. The Parameters. AddWithValue (" stars, "starsnum); CMD. ExecuteNonQuery (); Conn. Close (); }