I have a foreach loop going that is adding e-mail address to an array. At the end I join the array and push it into a string.
I have an issue when someone in the database has a blank email address it messes up my logic. Can someone help me fix this?
TestGuy1:
TestGuy2: [email protected]
TestGuy3: [email protected]
With the above information it creates a 3 length array and then turns it into a string like so:
sEmailList "[email protected],[email protected]," string
Code:
DataTable GetUserReportsToChain = objEmployee.GetUserReportsToChain(LoginID, ConfigurationManager.AppSettings.Get("Connection").ToString());
int RowCount = GetUserReportsToChain.Rows.Count;
string[] aEmailList = new string[RowCount];
int iCounter = 0;
foreach (DataRow rRow in GetUserReportsToChain.Rows)
{
if (rRow["usrEmailAddress"].ToString() != "")
{
aEmailList[iCounter] = rRow["usrEmailAddress"].ToString();
iCounter++;
//String email = rRow["usrEmailAddress"].ToString();
}
}
string sEmailList = String.Join(",", aEmailList);
Any idea how I can fix this when the database has a blank value for e-mail?
rRow["usrEmailAddress"].ToString()==""is true then there are empty slots inaEmailListnot set to an email address.