Quote:
Originally Posted by norman001
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.