I’m using Visual C# 2010 express windows form application & Mysql for DB.
I want to get a value (current no of students) from DB and increase it by 1 and update that value. for that I use the below code, but I’m getting an error called “unknown column ‘x’ in ‘field list’.
connection.Open();
MySqlCommand cmd1 = new MySqlCommand("SELECT NoOfStudents FROM batch", connection);
MySqlDataReader dr = null;
dr = cmd1.ExecuteReader();
int x;
while (dr.Read())
{
x = Convert.ToInt32(dr[0]);
x = x + 1;
}
dr.Close();
MySqlCommand cmd2 = new MySqlCommand("UPDATE batch SET NoOfStudents= x", connection);
cmd2.ExecuteNonQuery();
connection.Close();
try this
x is a variable declared in your program and Mysql dont know any thing about it, this is just a string and its content is ignored by the compiler