Snertill
asked on
Webservice: return multiple rows using SQLDataReader.
Hi, this is my first webservice
here is some code im making
SqlDataReader itemData = sqlCmd.ExecuteReader();
if (itemData.Read())
{
while (itemData.Read())
{
item.Author = itemData.GetString(0);
item.Date = itemData.GetString(1);
}}
return item;
Is thera a way to store each row until while loop has finished and return all rows at in one go?
this returns the last or only row.
here is some code im making
SqlDataReader itemData = sqlCmd.ExecuteReader();
if (itemData.Read())
{
while (itemData.Read())
{
item.Author = itemData.GetString(0);
item.Date = itemData.GetString(1);
}}
return item;
Is thera a way to store each row until while loop has finished and return all rows at in one go?
this returns the last or only row.
Store the data in a data set or custom collection and read the data into it. Then return the data set.
ASKER
thanks,
but I'm more looking for solution that does not involve datasets.
Not that I dont like datasets, just interessed in this approach for now.
but I'm more looking for solution that does not involve datasets.
Not that I dont like datasets, just interessed in this approach for now.
Won't the nature of the logic in the above While loop ALWAYS set item.Author and item.Date to the last occurrence of data in the Reader?
If you're planning on sending this data somewhere from a method, you'll have to return something that allows for multiple rows...hence the DataSet or Collection suggestion.
Or maybe, I'm missing something. Can you clarify a little more here?
If you're planning on sending this data somewhere from a method, you'll have to return something that allows for multiple rows...hence the DataSet or Collection suggestion.
Or maybe, I'm missing something. Can you clarify a little more here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is worth the try, Thanks.
Datasets works well, but I will test this collection approach
Datasets works well, but I will test this collection approach
The collection approach is my preference becuase you can treat the objects as typed objects not as Data Set values.