Property declarations in Classes

  • Thread starter Thread starter Ratman
  • Start date Start date
R

Ratman

With Option Strict On, I am getting errors on the areas highlighted
below. Does anyone have a solution to this? The mouse over states
the following..." 'Is' requires operands that have reference types,
but this operand has the value type 'System.Data.SqlTypes.SqlString'."

Private sUsername As SqlString

Public Property Username() As SqlString
Get
Return sUsername
End Get
Set(ByVal --->Value<--- As SqlString)
If (Value Is System.DBNull.Value) Then
sUsername = New System.Data.SqlTypes.SqlString("")
Else
sUsername = New
System.Data.SqlTypes.SqlString(--->Value<---)
End If
End Set
End Property

Thanks in advance,

Jake
 
Try replacing:
Value is System.DBNull.Value
with:
Value = SqlString.Null
 
Public Property Username() As SqlString
Get
Return sUsername
End Get
Set(ByVal Value As SqlString)
If (--->Value = SqlString.Null<---) Then
sUsername = New System.Data.SqlTypes.SqlString("")
Else
sUsername = New
System.Data.SqlTypes.SqlString(--->Value<---)
End If
End Set
End Property

Thanks but that did not work. Any other ideas?

Jake
 
Ratman,
In addition to Juan's comments. Remember that SqlString is a value type, so
it behaves largely like an Integer.

To check to see if it is null you can use the IsNull instance method of it.

Seeing as you already have a SqlString as a parameter, there is no need to
create a second one to save the none null value, as SqlString has no
constructor that accepts an SqlString.

Try something like:
Public Property Username() As SqlString
Get
Return sUsername
End Get
Set(ByVal value As SqlString)
If (value.IsNull) Then
sUsername = New System.Data.SqlTypes.SqlString("")
Else
sUsername = value
End If
End Set
End Property

Which simply saves non-null values otherwise saves a new empty SqlString.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top