|
|
Must Implement IConvertible With Microsoft Data Application BlockIConvertible Error | | What causes "Must Implement IConvertible With Microsoft Data Application Block" error? Searching the web will produce as many solutions as questions and they are not all the same. Obviously, this error can be caused by multiple things, but it has caught me twice lately and I thought I might share the cause in my case. In fact, it caught me twice in a month for the same reason and the inordinate time that it took me to fix it the second time would lead one to question, "How often do I have to be retrained?"
In my case it has always been caused when I am passing a parameter array to the MS Application Block, SQLHelper. For example, take the following code sequence that builds a SqlParameter Array and then passes it to the SqlHelper.
Dim arParams(1) As SqlParameter
AddSqlParm(arParams(0), "@Customer", SqlDbType.Char, _
gblCustid.Trim, 8)
AddSqlParm(arParams(1), "@ReturnParm", SqlDbType.Int, "O")
SqlHelper.ExecuteNonQuery(ConnectionString, _
"usp_MyStoredProc", arParm)
|
In the example above, the parameter array is built by AddSqlParm method, which is not germaine to this article. Just know that it is an overloaded method for building SQL parameters into an array. The next line of code is calling a method which will call the stored procedure. The call to the stored procedure caused an exception, "Must implement IConvertible..." After comparing my call to SQLHelper against others that were doing the same thing, for a time period longer than I will admit to, I finally saw that I was using the wrong SQLHelper Overload method. Changing the call to SQLHelper to the following line will correct the problem.
SqlHelper.ExecuteNonQuery(ConnectionString, _
CommandType.StoredProcedure, _
"usp_MyStoredProc", arParm)
|
Notice that the call line shown immediately above has an extra parameter specifying the CommandType.StoredProcedure, which is required when passing a parameter array to SQLHelper. Calling the correct overload immediately solved the problem. I hope this will help someone, but I am really writing this article to remind myself the next time I run into the problem. Remember, I have to be re-trained....
| Ask a Question, or give your feedback on my articles or products by clicking on My Blog. |  |
|
|