· Chris Hammond
Last Updated
Microsoft Enterprise Library Data Access Application Blocks Execute Reader (Object must implement IConvertible)
Learn how to successfully use the MS Enterprise Library Data Access Application Blocks for executing readers with this helpful code snippet and resources.
![Learn how to successfully use the MS Enterprise Library Data Access Application Blocks for executing readers with this helpful code snippet and resources.](/_astro/2024shots-2.dme1yDgr_Z1fXKq.webp)
I’ve been trying to get the MS Enterprise Library Data Access Applications Blocks working this morning. Yesterday I got the library set up and running. I started to implement the DAAB so that I could call a stored procedure, passing in a parameter, and retrieving a DataReader
that I could fill into a class. But I was having some horrible problems trying to get the stored procedure to run and fill the DataReader
using the DAAB.
I was continually getting the error:
“Object must implement IConvertible”
and was unable to figure out why this was.
sqlCommand = "spCMS_CustomerLostPasswordEmailAddress";
// Parameters
SqlParameter[] parms = {
new SqlParameter("@EmailAddress", SqlDbType.VarChar, 50)
};
parms[0].Value = identifier;
DBCommandWrapper dbcw = db.GetStoredProcCommandWrapper(sqlCommand, parms);
SqlDataReader dr = db.ExecuteReader(dbcw);
It would return the error while trying to perform the ExecuteReader
command.
Solution
In order to get the code to successfully function, I had to do the following:
DBCommandWrapper dbcw = db.GetStoredProcCommandWrapper("spCMS_CustomerLostPasswordEmailAddress");
dbcw.AddInParameter("@EmailAddress", DbType.String, identifier);
SqlDataReader dr = (SqlDataReader)db.ExecuteReader(dbcw);
So if you’re looking to use ExecuteReader
with the Microsoft Enterprise Library Data Access Application Blocks, I hope the above code helps!
Resources I used to figure all of this out:
- Enterprise Library / Data Access Application Block Follow-up
- An Introduction to the Microsoft Enterprise Library by Scott Mitchell