i build a web service with Visual Studio 2010. the Language is C# and ASP.NET 3.5.
the Webserver sends the data from my ms sql server 2008 to an iPhone with JSON format.
but i receive one string value with all the data from SQL Server.
i want that the web service sends me the data separate so that i can consume it better on the iPhone.
here is my c# class:
namespace WebService1
{
public class RaumklassenHelper
{
internal static string Raumklasse()
{
string raumKlassenObject = "";
using (SqlConnection con = new SqlConnection(@"Data Source=Localhost\SQLEXPRESS;Initial Catalog=BOOK-IT-V2;Integrated Security=true;"))
using (SqlCommand cmd = new SqlCommand(@"SELECT BEZEICHNUNG FROM RAUMKLASSE", con))
{
con.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
if (rdr["BEZEICHNUNG"] != DBNull.Value)
{
raumKlassenObject += rdr["BEZEICHNUNG"].ToString();
}
}
}
}
return raumKlassenObject;
}
}
}
here is my web method:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string Raumklasse()
{
return RaumklassenHelper.Raumklasse();
}
how can send the strings spereate ?
You could return an array:
and then obviously adapt the data retrieval method: