Home executescalar: Object cannot be cast from DBNull to other types
Reply: 0

executescalar: Object cannot be cast from DBNull to other types

user733
1#
user733 Published in August 15, 2018, 9:02 am

I'm having a problem when there is no data/value is fetch during running the program, I get the following error:

Object cannot be cast from DBNull to other types.

I tried validating it using if dr.hasrow() but I still get errors.

drqry = "SELECT max(num) FROM tbCVinfo WHERE cvno LIKE '%" & cvstr & "%'"

cmd2.CommandText = drqry
cmd2.Connection = con

Dim result As String = ""

cv = Convert.ToInt32(cmd2.ExecuteScalar())
'''''''''in this section I'm getting the error.

cv = cv + 1
If cv >= 0 And cv <= 9 Then
  ...............
Else
    cn = "0001"
End If
cn = result

cvno = cn
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300946 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO