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

CodePudding user response:

The
reference 1/f, one tree forest _ 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 ();
}


But the field called test value has not been updated? How to update its value, such as its value is 0, now update it for 1

CodePudding user response:

 
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 +"=@ stars where userid='" + id + "' ", conn);
CMD. The Parameters. AddWithValue (" stars, "starsnum);
CMD. ExecuteNonQuery ();
Conn. Close ();
}
  • Related