?
Solved

loop thru fields in a dataset

Posted on 2008-06-13
8
Medium Priority
?
289 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 200 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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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