Hi,

I have a DataTable oDT.

oDT is populated from SQL Server with 6 columns including a column "bAAA" of varbinary(200)

I have a function fx(ByVal byteArray As Byte()) as String

I would like to add a calculated column to oDT something like this:

oDT.Columns.Add("sAAA", GetType(String), fx(bAAA)) 
'bAAA is not declared

oDT.Columns.Add("sAAA", GetType(String), fx("bAAA".ToArray)) 
'1-dimensional array of char cannot be converted to 1-dimensional array of type byte

oDT.Columns.Add("sAAA", GetType(String), fx("bAAA")) 
'value of type string cannot be converted to 1-dimensional array of type byte

oDT.Columns.Add("sAAA", GetType(String), "fx(bAAA)") 
'(runtime) undefined function fx

fx() is known to work when bAAA is returned as an output parameter by a sproc.
i.e.
fx(oCmd.Parameters("@bAAA").Value).ToString
does indeed produce the required string.

:( any suggestions?

is there really no better way than pulling Server data into tempDT and then:

With tempDT
  For c=0 to .Columns.Count -1
    If .Columns(c).ColumnName = "bAAA" Then
      oDT.Columns.Add("sAAA", GetType(String))
    Else
      oDT.Cloumns.Add(.Columns(c).ColumnName, .Columns(c).GetType)
    End If
  Next
  For Each temprow In .Rows
    Dim newrow as DataRow = oDT.NewRow
    If .Columns(c).ColumnName = "bAAA" Then
      newrow("sAAA") = fx(tmprow(c))
    Else
      newrow(c) = tmprow(c)
    End If
    oDt.Rows.Add(newrow)
  Next
End With

...it seems really clunky to do it this way.

above was total rubbish.
a slightly less clunky route:

With oDT
	.Columns.Add("sAAA", GetType(String))
	For Each dtrow in .Rows
		dtrow("sAAA") = fx(dtrow("bAAA"))
	Next dtrow
	.Columns.Remove("bAAA")
End With
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.