sqlnewbie
sqlnewbie

Reputation: 867

VB Script CSTR alternative in VB.NET

CStr in VB script throws error when NULL value is passed to it, whereas CStr in VB.NET ignores null value and doesn't throw error.

Is there any other function which does same function as CStr in VB script.

 Try
     Dim str As String
     str = Nothing
     'assuming above line will set str to null.

     Dim x As String

     x = CStr(str)

     ' I am expecting CStr above should throw exception as it does in VBScript.
   Catch ex As Exception

  End Try

Thanks and Regards, PV

Upvotes: 0

Views: 1230

Answers (1)

Oded
Oded

Reputation: 499042

Use ToString() in order to get a string representation of an object.

This is invoked on the object itself:

MyVariable.ToString()

Note that for many objects this will return the type of the object - you need to give more details regarding what exactly you are trying to do and with what objects.

Upvotes: 1

Related Questions