The ASPSmith's Blog

Some rants about ASP.NET by Steven Smith

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!

Comments

Diego Gonzalez said:

Hi,

This problem is solved in the DAAB 3.0, you can find it <a here="http://www.gotdotnet.com/Community/Workspaces/Workspace.aspx?id=c20d12b0-af52-402b-9b7c-aaeb21d1f431"></a>

The problem is because you are specifying a SqlParameter[], but the method being called is the one with "params object[]", check it. I don't know why the CLR finds that method to call instead the one with SqlParameter[]. Anyway.... you can swith to the new version or, if you don't want to do so, check the method "AssignParameterValues" and just apply the same changes.

Luck,
DiegoG
# August 19, 2003 1:37 PM

Cinil said:

Got stuck with this error..Can anyone please help me out?
# September 29, 2003 11:01 AM

Colin said:

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.
# March 18, 2004 4:40 PM

Han said:

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++;
}
# April 21, 2004 1:46 AM

Han said:

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??
# April 21, 2004 1:55 AM

Terry Amusa said:

It works, CommandType.StoredProcedure has removed the bug

Cheers

Terry
# June 1, 2004 7:21 AM

Kingsley Tagbo said:

Found the same problem with SqlHelper.ExecuteNonQuery. I will add a CommandType.StoredProcedure Parameter and see if it makes a difference
# June 8, 2004 7:14 AM

Pete M said:

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

Cheers,

Pete
# June 14, 2004 4:50 AM

Kiran said:

Can any one help me
# June 30, 2004 6:40 AM

Paurav said:

Oh man. I've been trying to find the solution for this for last 2 hours. Thanks alot.
# July 20, 2004 6:21 PM

Chris Love's Official Blog - Professional ASP.NET said:

I get this error from time to time and I must admint is is now a legacy bug I propogated through my first Code Smith templates to generate my businesss logic. The problem is a simple one to overcome.

# September 30, 2006 9:20 PM

was lost said:

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

# August 23, 2007 5:05 PM

Venu Menon said:

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

# August 13, 2008 2:18 AM

David said:

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

<asp:Parameter Name="RowId" Type="String" />

to

<asp:Parameter Name="RowId" />

In my <UpdateParameters> section.  Hope this helps.

# June 13, 2009 7:07 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)