Error Message ambiguous method or properties

Posted on 2009-02-10
Last Modified: 2013-11-26
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();



		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




		return @params;


Open in new window

Question by:MoniMatthews
    LVL 3

    Accepted Solution

    modify to this in your code :

    precision = Math.Min(Convert.ToByte(row["NumericPrecision"].ToString()),(byte) 4);
    LVL 59

    Expert Comment

    by:Kevin Cross
    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now