Solved

loop thru fields in a dataset

Posted on 2008-06-13
8
275 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

18 Experts available now in Live!

Get 1:1 Help Now