protected void AddParameterWithName(DbCommand command, string parameterName, object value)
        {
            if (command.Parameters.GetType().Name == "SqlParameterCollection")
            {
                // The SqlParameterCollection only accepts SqlParameter objects, can't add value types directly

                SqlDbType parameterType = SqlDbType.NText;

                if (value is Type)
                {
                    if ((Type)value == typeof(int))
                    {
                        parameterType = SqlDbType.Int;
                    }
                    else if ((Type)value == typeof(DateTime))
                    {
                        parameterType = SqlDbType.DateTime;
                    }
                    else if ((Type)value == typeof(bool))
                    {
                        parameterType = SqlDbType.Bit;
                    }
                    else if ((Type)value == typeof(double) || (Type)value == typeof(float))
                    {
                        parameterType = SqlDbType.Float;
                    }
                    else if ((Type)value == typeof(decimal))
                    {
                        parameterType = SqlDbType.Money;
                    }
                    else if (!((Type)value == typeof(string)))
                    {
                        throw new Exception("Unhandled parameter type in AddParameterWithName: " + value.GetType().Name);
                    }
                    value = DBNull.Value;
                }
                else if (value is int)
                {
                    parameterType = SqlDbType.Int;
                }
                else if (value is DateTime)
                {
                    parameterType = SqlDbType.DateTime;
                }
                else if (value is bool)
                {
                    parameterType = SqlDbType.Bit;
                }
                else if (value is double || value is float)
                {
                    parameterType = SqlDbType.Float;
                }
                else if (value is decimal)
                {
                    parameterType = SqlDbType.Money;
                }
                else if (!(value is string))
                {
                    throw new Exception("Unhandled parameter type in AddParameterWithName: " + value.GetType().Name);
                }

                System.Data.SqlClient.SqlParameter parameter = null;

                if (parameterType == SqlDbType.NText)
                {
                    int textLength = 256 * 2;
                    if (value != DBNull.Value)
                    {
                        textLength = (value as string).Length * 2; // ntext / unicode buffer

                        // establish a minimum amount of even 256-byte blocks that this string will fit in

                        textLength += 2; // terminating zero, in unicode
                        textLength -= (textLength % 256);
                        textLength += 256;
                    }
                    parameter = new System.Data.SqlClient.SqlParameter("@" + parameterName, parameterType, textLength);
                }
                else
                {
                    // For all other types, ignore the length parameter, let the default handle it

                    parameter = new System.Data.SqlClient.SqlParameter("@" + parameterName, parameterType);
                }

                parameter.Value = value;

                System.Data.SqlClient.SqlParameterCollection sqlCollection =
                    command.Parameters as System.Data.SqlClient.SqlParameterCollection;

                sqlCollection.Add(parameter);
            }
            else if (command.GetType().FullName == "MySql.Data.MySqlClient.MySqlCommand")
            {
                MySqlParameter newParameter = new MySqlParameter(parameterName, value);
                command.Parameters.Add(newParameter);
            }
            else
            {
                int i = command.Parameters.Add(value);

                if (command.GetType().FullName == "System.Data.OracleClient.OracleCommand")
                {
                    command.Parameters[i].ParameterName = ":" + parameterName;
                }
                else
                {
                    command.Parameters[i].ParameterName = "@" + parameterName;
                }
            }
        }