473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

concatinating rows returned from ADO select into a single string?

jc
I might be able to do this in t-sql, but is there an easy way to do
this in vb.net/ado.net?

Say my function looks like this:

Public Function GetDataSet(ByVal sql As String) As DataSet

If _connected = True Then
Dim da As New SqlDataAdapter(sql, _cnn)
Dim ds As New DataSet

da.Fill(ds)
Return ds
End If
Return Nothing

End Function
and may return a dataset with 5 rows max. I'd like to take the result
from one of the columns and concatinate them into a single string and
return that.

Thanks for any help!
Jul 23 '08 #1
3 1202
>>
Public Function GetDataSet(ByVal sql As String) As DataSet

If _connected = True Then
Dim da As New SqlDataAdapter(sql, _cnn)
Dim ds As New DataSet

da.Fill(ds)
Return ds
End If
Return Nothing

End Function
<<

'--change your function as follows:

Public Function GetDataSet(ByVal sql As String) As String

If _connected = True Then
Dim da As New SqlDataAdapter(sql, _cnn)
Dim ds As New DataSet

da.Fill(ds, "tbl1")
dim str1 as string
for each dr as datarow in ds.Tables("tbl1").rows
if str1 <"" then str1 &= ","
str1 &= dr("desiredCol").ToString
next
Return str1
End If
End Function
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '08 #2
On Jul 23, 5:31*pm, jc <j...@webdos.comwrote:
I might be able to do this in t-sql, but is there an easy way to do
this in vb.net/ado.net?

Say my function looks like this:

* * *Public Function GetDataSet(ByVal sql As String) As DataSet

* * * * * * If _connected = True Then
* * * * * * * * Dim da As New SqlDataAdapter(sql, _cnn)
* * * * * * * * Dim ds As New DataSet

* * * * * * * * da.Fill(ds)
* * * * * * * * Return ds
* * * * * * End If
* * * * * * Return Nothing

* * * * End Function

and may return a dataset with 5 rows max. I'd like to take the result
from one of the columns and concatinate them into a single string and
return that.

Thanks for any help!
Instead of using a dataadapter and filling a dataset, instead using a
datareader and use that to loop through the results. For the string
concatenation, you will want to use a stringbuilder for best
performance.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Jul 24 '08 #3
jc,

I made this morning here this message, I never saw it.

\\\
Public Function GetDataSet(ByVal sql As String, ByVal wantedColumn as
integer) As String
If _connected = True Then
Dim da As New SqlDataAdapter(sql, _cnn)
Dim dt As New DataTable
Dim myString as String
da.Fill(dt)
for each dr as DataRow in Dt.Rows
myString = myString &
dr.item(wantedColumn).ToString & ";"
next
Return myString.Substring(0, myString.Length - 1)
End If
End Function
///

This is not tested and is typed here.

You are using only 5 rows, so the purpose of the StringBuilder is low,
however as you have wide columns you better can use the stringbuilder
instead of the concatination of the string.

Cor
"jc" <jo**@webdos.comschreef in bericht
news:ca**********************************@s50g2000 hsb.googlegroups.com...
>I might be able to do this in t-sql, but is there an easy way to do
this in vb.net/ado.net?

Say my function looks like this:

Public Function GetDataSet(ByVal sql As String) As DataSet

If _connected = True Then
Dim da As New SqlDataAdapter(sql, _cnn)
Dim ds As New DataSet

da.Fill(ds)
Return ds
End If
Return Nothing

End Function
and may return a dataset with 5 rows max. I'd like to take the result
from one of the columns and concatinate them into a single string and
return that.

Thanks for any help!
Jul 24 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lord Merlin | last post by:
How do I add up the values of the data from all of the rows returned? i.e - I have a DB, with 148 rows of client info, and I want to addup all the scores. Each entry's score differes. Here is the...
9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
5
by: Jerry | last post by:
I have a need to concatenate all Descriptions from a select statement SELECT t_ReviewSection.PeerRevSectionDescription FROM t_ReviewSection WHERE t_ReviewSection.PeerRevID = @lngRevID...
6
by: yoohanman | last post by:
Hi, I have a select statment that correctly returns zero rows at times. I would like to be able to return the value 0 (a single row with the value 0) whenever the logic returns zero rows. ...
2
by: Vagabond Software | last post by:
I'm at a complete loss on this problem. I'm using a DataColumn Expression with the DataTable Select method to return rows matching a data. Rows are returned on my Windows XP Professional computer...
2
by: Andrew | last post by:
Hey all, Have a strange one here, and being still fairly new to .NET isn't helping me understand it. I am having a problem where a DataReader doesn't return all the rows when I try to use a...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
2
by: Blasting Cap | last post by:
I've got a gridview (that I converted over from a datagrid, which had been working properly), that is doubling up the number of rows returned. When it was running as a datagrid, the same code sent...
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.