I want to return an array of Strings in the form \"abc#xyz#ghi#tru\" (where # is delimiter) from my web service method . However i m not able to do it . Here is my current web s
[WebMethod]
public string getData()//changed to return string
{
SqlConnection myConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=student;User ID=sa;Password=123");
try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "select name from names";//you can make it select distinct
SqlDataReader myReader = myCommand.ExecuteReader();
string toReturn = "";
while(myReader.Read())
{
if (myReader.Read())
{
toReturn += myReader["name"].ToString() + "#";
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
myConnection.Close();
}
return toReturn; //# as delimiter
}