In my C # WCF service, I have a SqlDataReader that contains data rows that I would like to return to the client.
How to return everything to SqlDataReader ?
I have now
if (sqlReader != null) { if (sqlReader.HasRows) { while (sqlReader.Read()) { return sqlReader[0].ToString(); } sqlConn.Close(); } else { return null; } }
This returns only the first result. The return type of the class is the string at the moment. I was thinking of something like an array in an array, but I'm not sure how?
EDIT:
Thanks for answers. I am interested in returning all the SQL data that the service creates. Offline first column ([0]) - this was for testing only.
But I'm not sure how to return everything from the service back to the client.
For example, in Powershell, I would create a collection and add objects to this collection if I had to transfer it between clients.
I am looking for something similar in C # and WCF.
Thanks so far :)
EDIT # 2:
Got!:)
A new class has been created (for example):
public class ObjectNotification { public string AlertDescription; public string Servername; }
In my svc.cs file above:
List<ObjectNotification> objlist = new List<ObjectNotification>();
and
if (sqlReader.HasRows) { while (sqlReader.Read()) { ObjectNotification obj = new ObjectNotification(); obj.AlertDescription = sqlReader["AlertDescription"].ToString(); obj.Servername = sqlReader["ComputerName"].ToString(); objlist.Add(obj); } } return objlist;
This gave me exactly what I wanted :)
Best wishes
source share