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

MoniMatthewsAsked:
Who is Participating?
 
shakashicoConnect With a Mentor .Net DeveloperCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.