Search code examples
vb.netrow

Correct Syntax for using LEFT in a ROW Statement in VB


I know this seems like a very elementary issue and forgive me, but I wasn't able to find the syntax.

For some reason VB doesn't like this syntax, what am I missing?

drNewPat.pzip5 = Left(row("zip"), 5)

I use a similar statement using Trim and it works fine.

drNewPat.gname = "Group Name: " + Trim(row("gname"))

Thanks again in advance!


Solution

  • .Net provides all sorts of handy String methods. Ont to get to know is .Substring. Old vb6 methods are usually not as good.

    Private Sub OPCode()
        Dim dt As New DataTable
        Dim row As DataRow
        row = dt.Rows(0)
        Dim s = row("zip").ToString.Substring(0, 5)
    End Sub