Hola
3ricks0ul, ese mensaje te arroja porque seguramente no tienes datos en tu tabla y al hacerle la funcion
MAX al
SQL te muestra
NULL y eso al hacerle el convert a Int32 en VB.NEt es
ERROR.. has esto en tu consulta :
Código vb:
Ver originalDim sql As String = "SELECT ISNULL(MAX(sort_num),0)" & _
"FROM sorting"
Nos cuentas! Saludos!

.
PDT :
Has lo mismo para tu funcion SORT