Hello I have a simple question that regards updating data into a MS MySql Database 2012 table. The table that I have is called COMPLETED and has 3 fields. student_ID (int, NOT allowed nulls) completed (bool, NOT allowed nulls) random_code (string, allowed nulls)
In c# I have a list filled with unique random codes. I want all codes updated into the database, so if I have 20 records I want 20 unique codes updated into the random_code field. So the first records gets the first code, the seconds records gets the second code and so on. I think the best way to do this is using a foreach and, for each code in the list of codes update that code into the random_code field in my database.
foreach (string unRaCo in codes)
{
//insert database
SqlCommand toDB = new SqlCommand("UPDATE COMPLETED SET random_code = '"+ unRaCo +"' ", conn);
SqlDataReader toDBR;
toDBR = toDB.ExecuteReader();
toDBR.Close();
}
The problem I have is that the update query updates ALL records with the first code, so the first record has the code 12345 for example but all other records also have that code. I want to update 12345 into record 1 and 54321 for example in number 2, how do I do that?