Solved

loop thru fields in a dataset

Posted on 2008-06-13
8
284 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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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