Invalid Cast Exception was unHandled MySQL

前端 未结 2 742
自闭症患者
自闭症患者 2021-01-23 05:24

When I run the program I get this error:

Invalid Cast Exception was unHandled

This is part of form for fill a database, and visual

2条回答
  •  遇见更好的自我
    2021-01-23 05:56

    The problem is the ExecuteScalar that in MySql returns an Int64 not an Int32. So the invalid cast when you use an explicit cast

    With a conversion your error should go away

     int UsuarioExiste = Convert.ToInt32(sqlCommand.ExecuteScalar());
    

    You are not alone to fall in this problem

    Of course everything that has been said in the answer from Mr Soner Gönül is still applicable and should be done ASAP.

提交回复
热议问题