Solved

loop thru fields in a dataset

Posted on 2008-06-13
8
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
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
 
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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