Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2009, 12:06 AM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Convert a dataset to a string

Hi,

How do I convert a dataset to a string variable?

Select categories from cattable where username='testuser'

This select statement returns a set categories (more than one) and I wanted to
assigned all the data to a one long string. When I try to do that it only returns
the first data item. How do I get all the rows? I look through the book and I can not find
examples..


Thanks,

Norman
 
Old March 4th, 2009, 02:44 AM
Authorized User
 
Join Date: Feb 2009
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by norman001 View Post
Hi,

How do I convert a dataset to a string variable?

Select categories from cattable where username='testuser'

This select statement returns a set categories (more than one) and I wanted to
assigned all the data to a one long string. When I try to do that it only returns
the first data item. How do I get all the rows? I look through the book and I can not find
examples..


Thanks,

Norman
Hi Norman

you can not convert dataset to string, because dataset is set of Tables.
and for your Query problem
your query returning all values, but you are capturing only first value,
To capture all values, you need to use data reader with while loop, not with If condition.

sample code I gave below
Code:
                 Dim sqlcom As SqlCommand, con As New SqlConnection("connection string"), sqldr As SqlDataReader
        Dim strresponse As String = String.Empty
        sqlcom = New SqlCommand("Select categories from cattable where username='testuser'", con)
        con.Open()
        sqldr = sqlcom.ExecuteReader
        With sqldr
            While .Read
                strresponse = strresponse & "," & .Item("categories")
            End While

            .Close()
        End With

        Response.Write(strresponse)
In the above code I am appending all categories to single string with comma(,) sepearated.
I think the above code will help you.
__________________
Rajendar
The Following User Says Thank You to rajendar434 For This Useful Post:
norman001 (March 4th, 2009)
 
Old March 4th, 2009, 06:46 AM
Registered User
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default regarding how to post?

HI

i want to know how to post

as i dont find any option to post my question

thats why i do like this

let me know any one how to post question?
 
Old March 4th, 2009, 10:30 AM
Authorized User
 
Join Date: Apr 2008
Posts: 26
Thanks: 6
Thanked 0 Times in 0 Posts
Default Convert a dataset to a string

Wow! What an elegant way to do this!

Thanks for your answer.

Norman

PS: If you want to post a question, just simply create a new thread!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Know how to convert a range to a string? rstober Excel VBA 5 September 12th, 2009 08:49 AM
convert to string prafullaborade XML 7 May 29th, 2008 02:59 PM
Convert string to Date rprasad012 ASP.NET 1.0 and 1.1 Basics 1 March 19th, 2008 07:07 AM
Problem with convert dataset to xml ram_kimi ASP.NET 1.0 and 1.1 Professional 0 May 19th, 2006 06:50 AM
Problem in convert Dataset to XML ram_kimi XML 0 May 19th, 2006 05:30 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.