Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail.To

Status
Not open for further replies.

crxcte1

Programmer
May 22, 2003
74
US
The code below catches errors due to the 3rd record in the database being empty. I know this is too simple but its getting the best of me.

while (drMembers.Read()) {
MyMail.To = drMembers.GetString(0);
if (MyMail.To != "") SmtpMail.Send(MyMail);
MyMail.To = drMembers.GetString(1);
if (MyMail.To != "") SmtpMail.Send(MyMail);
MyMail.To = drMembers.GetString(2);
if (MyMail.To != "") SmtpMail.Send(MyMail);
}
 
The datareader GetString() method does not do a conversion, which means that the database entry must already be a string or an exception is thrown. A database null value is not considered a string so use SqlDataReader.IsDBNull() to test before using it. Perhaps better yet, do something like this:

drMembers["index_name"].ToString()

to convert it in one quick swoop, in case you don't care to do anything special if it is empty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top