Link to home
Start Free TrialLog in
Avatar of CraigLazar
CraigLazar

asked on

loop thru fields in a dataset

Hi,
I need to build a string value based on the fields in my dataset.
So if there are say 3 or 9 fields in the datset row, i need to loop thru the fields and then simply add them to a string

thanks
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello CraigLazar,

Dim MyString As String = String.Join(",", MyDataSet.Tables(0).Rows(0).ItemArray)

For example.

Regards,

TimCottee
Avatar of CraigLazar
CraigLazar

ASKER

Hi Tim
i get this error

code
Dim MyString As String = String.Join(",", tmpds.Tables(bs.DataMember).Rows(0).ItemArray)

"Unable to cast object of type 'System.Object[]' to type 'System.String[]'."
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi i thought as much, and thats what i have done
thanks man
have a good weekend

cheers
CraigLazar,

You too, let's hope the sun shines!

TimCottee
hi Tim, sorry hope u do not mind me asking u anoterh question on the same line here - how would i get the same field information of a bindingsource object? cause i take my dataset and i give it to a bindingsource object for the form

thanks
CraigLazar,

Good question, I would suggest that you try explicitly casting it. Something along the lines of:

        For Each itmData As Object In CType(MyObject.BindingSource,System.Data.DataSet).Tables(0).Rows(0).ItemArray

TimCottee
ok i hacked atround and got this working :)

tmpDataString = getRowData(drv.Row.ItemArray())

wehre getRowData is my little array looping function

cheers