I'm new on server's technique. I'm connecting a mobile phone with an application server, and aplication server is communicate locally with an sql server.
Is there any method to send and read columns from sql server? I mean till now i'm sending all columns in a string separated with comma.
When client will take that string it separate them and filling a list or listview...
Example my string has this form: John,24,1st class
and my client contain this class
public class objects()
{
public string Name{get;set;}
public string Age{get;set;}
public string SchoolClass{get;set;}
}
So when i'm getting response i'm filling each value from my string on each list object.
Is there any other method more effective and faster than this?
var web = new HttpListener();
web.Prefixes.Add("http://localhost:8080/");
Console.WriteLine("Listening..");
web.Start();
Console.WriteLine(web.GetContext());
var context = web.GetContext();
var response = context.Response;
string responseString = "";
using (SqlConnection connection = new SqlConnection(connectionString)
{
connection.Open();
using(SqlCommand cmd = new SqlCommand("Select name,age,SchoolClass from Students",connection))
using(SqlDataReader read=cmd.ExecuteReader))
{
while(read.Read())
{
responseString +=read["Name"].ToString() + ",";
responseString +=read["Age"].ToString() + ",";
responseString +=read["SchoolClass"].ToString() + ",";
}
}
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
Console.WriteLine(output);
output.Close();
web.Stop();
Console.ReadKey();