Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
"get_email_id_user_rolewise" is my stored procedure, it returns 11 emailid's list in single column only from my database table, so i want to know if i write below code then what i return in email string at last line of this code?

C#
command.CommandText = "get_email_id_user_rolewise";
command.Parameters.AddWithValue("@circle", circle);
reader = command.ExecuteReader();
string email = "";
while (reader.Read())
{
     email = reader[0].ToString();
}
return email;


What I have tried:

i have tried above code but cant get result, because my mobile application is not working currently.
Posted
Updated 17-Feb-17 1:17am
v3

You are returning the last item.
 
Share this answer
 
Comments
Maciej Los 17-Feb-17 8:30am    
5ed!
CPallini 17-Feb-17 11:47am    
Thank you!
create an array of email then return the array and then you can print it out using for loop in single column
 
Share this answer
 
If you would like to return all emails, try this:

C#
StringBuilder sb = new StringBuilder();
while (reader.Read())
{
     sb.Append(reader[0].ToString() + "; ");
}
return sb.ToString();


Above code should return a list of emials separated by ";", for example: "JohnDoe@g.com; JaneDoe@h.com; ...; AliBabaAnd40Robbers@z.com"

For further details, please see: StringBuilder Class (System.Text)[^]
 
Share this answer
 
Comments
Member 12954126 17-Feb-17 8:27am    
Thanks for the help...
Maciej Los 17-Feb-17 8:30am    
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900