Solved

loop thru fields in a dataset

Posted on 2008-06-13
8
281 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:CraigLazar
  • 4
  • 4
8 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 21777093
Hello CraigLazar,

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

For example.

Regards,

TimCottee
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 21777179
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[]'."
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 21777200
CraigLazar,

I have to admit I didn't test it and wondered whether that might be a problem.

In that case you may have to do it the old fashioned way (sort of).

        Dim sbData As StringBuilder = New StringBuilder
        For Each itmData As Object In ds.Tables(0).Rows(0).ItemArray
            sbData.Append(",").Append(CType(itmData, String))
        Next
        Dim MyString As String = sbData.ToString.Substring(1)

TimCottee
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 21777821
hi i thought as much, and thats what i have done
thanks man
have a good weekend

cheers
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 43

Expert Comment

by:TimCottee
ID: 21777824
CraigLazar,

You too, let's hope the sun shines!

TimCottee
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 21777972
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
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21777998
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
0
 
LVL 4

Author Comment

by:CraigLazar
ID: 21778774
ok i hacked atround and got this working :)

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

wehre getRowData is my little array looping function

cheers
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now