Home Forums SQL Server 2005 Administering Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query. RE: Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.

  • Hi,

    We got the solution. We changed our code in DataAccess Layer.Correct code is below.

    Thanks for your help:)

    public void AddParameter(DbCommand cmd, Database db)

    {

    if (Parameters != null)

    {

    foreach (DictionaryEntry param in Parameters)

    {

    if (param.Value.GetType() == typeof(string))

    {

    db.AddInParameter(cmd, param.Key.ToString(), DbType.String, param.Value);

    }

    if (param.Value.GetType() == typeof(int))

    {

    db.AddInParameter(cmd, param.Key.ToString(), DbType.Int32, param.Value);

    }

    if (param.Value.GetType() == typeof(decimal))

    {

    db.AddInParameter(cmd, param.Key.ToString(), DbType.Decimal, param.Value);

    }

    }

    }

    }