0

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?

1
Contributor
2
Replies
4
Views
6 Years
Discussion Span
Last Post by izyrider
0

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.

0

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

Edited by izyrider: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.