Object Must Implement IConvertible with MS Data Access Application Block

Ran into this bug today.  I'm not the first, as a quick goole search found:

Google group thread.

Ted Graham also wrote about it, specifically for Access.

I think I'm close to finding the actual bug in the C# version of the DAAB, but I don't have time to totally fix it just yet.  However, I did find a workaround that I hope will help some folks.  I was calling a stored procedure like so:

return SqlHelper.ExecuteDataset(ConnectionString, "usp_ListAuthors", sqlArgs).Tables[0];

All I did to fix it was switch to another overload:

return SqlHelper.ExecuteDataset(ConnectionString, CommandType.StoredProcedure, "usp_ListAuthors", sqlArgs).Tables[0];

Simply specifying the CommandType fixed it.  I'm sure the other version has a bug in it - if you have the exact fix, I'd love to hear it.

Thanks!

12 Comments

  • Got stuck with this error..Can anyone please help me out?

  • Or, the simple fix is to change line 93 to read:

    commandParameters[i].Value = ((SqlParameter)parameterValues[i]).Value;



    instead of:

    commandParameters[i].Value = parameterValues[i];



    Version 1 of the DAAB (sqlhelper) was putting a parameter into the value of the other parameter.

  • help



    my daab version is so different from u guys...

    here's the code



    foreach(SqlParameter commandParameter in commandParameters)

    {

    // Check the parameter name

    if( commandParameter.ParameterName == null ||

    commandParameter.ParameterName.Length <= 1 )



    throw new Exception(

    string.Format(

    "Please provide a valid parameter name on the parameter #{0}, the ParameterName property has the following value: '{1}'.", i, commandParameter.ParameterName ) );

    if (dataRow.Table.Columns.IndexOf(commandParameter.ParameterName.Substring(1)) != -1)

    commandParameter.Value = dataRow[commandParameter.ParameterName.Substring(1)];

    i++;

    }

  • ok..i found the code already n i had made the ammendments..unfortunately...it said SPECIFIED INVALID CAST...



    did any1 have the same issues like me??

  • It works, CommandType.StoredProcedure has removed the bug



    Cheers



    Terry

  • Found the same problem with SqlHelper.ExecuteNonQuery. I will add a CommandType.StoredProcedure Parameter and see if it makes a difference

  • Thanks very much guys! Ive been tearing my hair out over this one.



    Cheers,



    Pete

  • Can any one help me

  • Oh man. I've been trying to find the solution for this for last 2 hours. Thanks alot.

  • adding the "CommandType.StoredProcedure " fixed my issue. thanks!

  • Thanks a lot ... CommandType.StoredProcedure has done the trick.... as someone already mentioned this issue had me pulling out my hair !!!

  • This happened to me once. All I ended up having to do was to change the following line:



    to



    In my section. Hope this helps.

Comments have been disabled for this content.