Conversion failed when converting ....

cortez081

New member
Joined
Mar 17, 2008
Messages
4
Programming Experience
Beginner
Hello, Is there any way to pass this error?

Conversion failed when converting the varchar value 'NULL' to data type int.

My Code:
VB.NET:
Dim employee As Integer
        employee = Row.EmployeeId
        Dim employeeString As String
        If employee > 0 Then
            employeeString = employee .ToString
        Else
            employeeString = "NULL"
        End If

Thanx!
 
Last edited by a moderator:
use an if statement to check the Row.EmployeeId for a null
VB.NET:
If Row.EmployeeId Is DBNull.Value Then employeeString = "NULL" Else employeeString = employee.ToString
 
use an if statement to check the Row.EmployeeId for a null
VB.NET:
If Row.EmployeeId Is DBNull.Value Then employeeString = "NULL" Else employeeString = employee.ToString

Wouldn't this pass the string "NULL"? I think you'd need to modify it to employeeString = Nothing.
 
Based on his code he's getting a null error and if the Id is less than 0 he's setting a null, so I figured if the EmpId is null then the string he would want to show a null as well. That's up to him to determine though.
 
Back
Top