• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

Error Message ambiguous method or properties

I am getting this error message:
The call is ambiguous between the following methods or properties: 'System.Math.Min(byte, byte)' and 'System.Math.Min(int, int)'

Below is my code:
I get the error on the precision =

private List<SqlParameter> createParametersFromColumns(string tableName, SqlConnection conn)
	{
		string sqlSelect = "select * from " + tableName;
		SqlCommand cmd = new SqlCommand(sqlSelect, conn);
		SqlDataReader r = cmd.ExecuteReader(CommandBehavior.KeyInfo);
		DataTable dt = r.GetSchemaTable();
		r.Close();
 
		SqlParameter param;
		string name;
		SqlDbType type;
		int size;
		bool nullable;
		byte precision;
		byte scale;
		List<SqlParameter> @params = new List<SqlParameter>(dt.Rows.Count);
 
		foreach (DataRow row in dt.Rows) 
        {
            name = row["ColumnName"].ToString();
			if (!_schemaAuthority.Contains(name)) continue; 
 
			type = (SqlDbType)Enum.Parse(typeof(SqlDbType), row["DataTypeName"].ToString(), true);
 
			size = Convert.ToInt32(row["ColumnSize"]);
			nullable = Convert.ToBoolean(row["AllowDBNull"]);
            precision = Math.Min(Convert.ToByte(row["NumericPrecision"].ToString()), 4);
 
			//call max out at precision=4 to account for all records that erroneously report precision as '255'
			scale = Convert.ToByte(row["NumericScale"]);
			param = new SqlParameter(name, type, size, ParameterDirection.Input, true, precision, scale, name, DataRowVersion.Original, null
			);
			@params.Add(param);
		}
		return @params;
	}

Open in new window

0
MoniMatthews
Asked:
MoniMatthews
1 Solution
 
shakashicoCommented:
modify to this in your code :

precision = Math.Min(Convert.ToByte(row["NumericPrecision"].ToString()),(byte) 4);
0
 
Kevin CrossChief Technology OfficerCommented:
shakashico is correct as the system compiler doesn't know for sure if 4 is meant to be a byte or an int in this case.  Casting to byte will make this clear.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now