Okay, in my database, users have a many-to-many relationship with the mailing list categories, so that each user can pick any number of categories that they want to receive Newsletters on. When viewing the list of categories that they can select, I do an OUTER JOIN in my SQL query so that I can retrieve ALL categories AND their "subscription" if they have one for that category.
Now, in my data access layer, I have a function that receives the recordset and assigns the values to the "strongly typed" model of the database...e.g.
Since I am using an OUTER JOIN, sometimes, the column oRset["subscrID"] exists, and other times it is equal to DBNull.Value, and still other times, when grabbing categories without the need to link it to user subscriptions, it's completely NULL and it throws the error System.IndexOutOfRangeException. It is the last error which is causing my only problem. In order to avoid it, I do this, which is (IMHO) bad programming practice because I have an empty catch:
Now, here I will state that I am normally a PHP developer, and if I were having a similar "Notice" error in PHP, I would simply prefix the reference oRset["subscrID"] with the @ symbol, because an "IndexOutOfRangeException" is not a problem in this case and I don't want it to end execution of the page...but neither do I want to do bad programming practices and get into the habit of writing empty catches...so anyone have a better solution???
Kevin
Now, in my data access layer, I have a function that receives the recordset and assigns the values to the "strongly typed" model of the database...e.g.
Code:
oCategory.Name = oRset["catName"].ToString();
Since I am using an OUTER JOIN, sometimes, the column oRset["subscrID"] exists, and other times it is equal to DBNull.Value, and still other times, when grabbing categories without the need to link it to user subscriptions, it's completely NULL and it throws the error System.IndexOutOfRangeException. It is the last error which is causing my only problem. In order to avoid it, I do this, which is (IMHO) bad programming practice because I have an empty catch:
Code:
try {
if( oRset["subscrID"] != DBNull.Value ) {
oCategory.RecipientRegistered = true;
}
}
catch( Exception e ) {
// do nothing, bad programming
}
Now, here I will state that I am normally a PHP developer, and if I were having a similar "Notice" error in PHP, I would simply prefix the reference oRset["subscrID"] with the @ symbol, because an "IndexOutOfRangeException" is not a problem in this case and I don't want it to end execution of the page...but neither do I want to do bad programming practices and get into the habit of writing empty catches...so anyone have a better solution???
Kevin