How to update in a table using mysql c # and a method?

0

Is it possible to use a method or class that uses table fields to do an update on this table?

For example: update record field 1 with f (record field2), record field1 with f (record2 field2), etc ...

reg|campo1|campo2
1    f(x)   x 
2    f(y)   y

Code would look something like:

string conectaBanco = "server = localhost; port = 3306; User Id = root; 
database=mysql; password=";
MySqlConnection objcon = new MySqlConnection(conectaBanco);
objcon.Open();

MySqlCommand objCmd = new MySqlCommand("tabela_A set campo1=?", objcon);
objCmd.Parameters.Add("@campo1", MySqlDbType.VarChar, 20).Value = 
metodo_qualquer(param1);
objCmd.ExecuteNonQuery();

Since metodo_qualquer() is executed with each record that is done the update

A more didactic example: A field of the DataNota table (field1) contains a student's responses to one test (ACDEB) and in another (field2) there is feedback (CCDAE). Field3 will contain the number of hits. So I need to update in field3 with the information of the number of hits that will be the result of the treatment of fields 1 and 2. For this there is a method (calcAcertos) that, given data field1 and field2, calculates the number of hits treating the " ACDEB "and" CCDAE ". Therefore, it is necessary to: update DataNote set field3 = calcAcerts (field1, field2)

Field1 = ACDEB Field2 = CCDAE Accounts = 2 Field3 = 2

    
asked by anonymous 23.04.2018 / 15:50

0 answers