Get affected rows on ExecuteNonQuery

后端 未结 5 1279
梦毁少年i
梦毁少年i 2020-12-01 17:35

I am currently working on a C# project and I am running an insert query which also does a select at the same time, e.g.:



        
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 18:19

    Be sure of one thing also You need to add a statement in the connection string For example:

    string const "Server=localhost; PORT=3306; Database=db; User id=root; password='';UseAffectedRows=True";
    MySqlConnection con = new MySqlConnection(const);
    con.Open();
    MySqlCommand cmd = new MySqlCommand(con);
    cmd.CommandText = "Update db set table = value where Column = value";
    int numberOfRecords = cmd.ExecuteNonQuery();
    

    Be sure of:

    UseAffectedRows=True
    

    so it will return a right value of rows affected

提交回复
热议问题