vb6 to vb.net Isnull not declared

itortu
itortu used Ask the Experts™
on
i need help converting this expression in vb6 to vb.net

OutCity = IIf(IsNull(drOCanada.Item("City"), "", drOCanada.Item("City")))

i get a message that reads" isNull not decalred"

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Try this



OutCity = IIf(drOCanada.Item("City").Equals(System.DBNull.Value), "", drOCanada.Item("City")))
Éric MoreauSenior .Net Consultant
Top Expert 2016
Commented:
even iif is not recommanded. suggested vb.net syntas should read:

if convert.isdbnull(drOCanada.Item("City")) then
   OutCity = ""
else
   OutCity = drOCanada.Item("City")
endif

Author

Commented:
thank you guys for your solutions.
i have a small question again, converting from vb6 the line below

TmpStr = String(PadLen, PadChr)

vb.net does not allow me to do it this way, how can that be replaced?

i hope you don't mind me merging two questions into one.

thank you.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Try this

TmpStr = PadChr.Substring(0, PadLen)
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
you need to use PadLeft ? PadRight. see http://www.java2s.com/Code/VB/Language-Basics/StringPadLeft.htm
Try this
TmpStr = StrDup(PadLen, PadChr)  'is faster

Also for you first question
IsNull is replased in vb.net by Is DBNull.Value

OutCity = IIf(drOCanada.Item("City") Is DBNull.Value, "", drOCanada.Item("City")))

Author

Commented:
hi guys, i am splitting the point in 3 equal parts, all of your answers have helped me so much i truly don't want to offend anyone.

i hope you understand.

thank you

Author

Commented:
i got just one more error in my program (well that is what i think)

i have this function:

Public Function GetStateByGeo(ByVal strGeo$) As DataSet

then i try to assign the dataset value to the function like this:

            If (Not IsNothing(ds)) Then
                If (ds.Tables(0).Rows.Count > 0) Then
                    GetStateByGeo = ds.Tables(0).Rows(0).ToString
                End If
            End If

but i get error:

Value of type 'System.Data.DataRow' cannot be converted to 'System.Data.DataSet'.      

how can the data set (recordset) can be assigned to the function ?

Author

Commented:
in the old vb6 code it was done this way:

Public Function GetStateByGeo(strGeo$) As ADODB.Recordset

  If Not rst Is Nothing Then
    If Not rst.EOF Or Not rst.BOF Then
      rst.MoveFirst
      Set GetStateByGeo = rst
    End If
  End If

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial