How to set comma after reading a email from a table?

Syedshakeer
Posted by Syedshakeer under C# category on | Views : 1524
SqlConnection conn=new SqlConnection("conn string");
conn.Open();
SqlCommand cmd = new SqlCommand("select FirstName from Employees", conn);
SqlDataReader dr = cmd.ExecuteReader();
string str = "";
string com = ",";
while (dr.Read())
{
str = dr["name"] + com + str;
}

output:
shakeer@gmail.com,hussain@rediffmail.com,Rama@yahoo.com,

Comments or Responses

Posted by: Kumarsudu on: 8/26/2009 Level:Starter | Status: [Member]
string str = "";
string com = ",";
while (dr.Read())
{
if(str!="")
{
str = dr["name"] + com + str;
}
else
{
str = dr["name"]
}
}

Hope this may help you

Thanks and Regards,
Kumar

Login to post response