-2

I am new to stored procedures. When i run this i get an error saying Error converting data type int to tinyint. In my C# was the following code:

mySqlcmd.CommandText = "EXECUTE PhoneNumber_Insert  @p_PhoneNumberTypeID, @p_PersonID";
mySqlcmd.Parameters.Add("@p_PhoneNumberTypeID", SqlDbType.TinyInt).Value = 1;
mySqlcmd.Parameters.Add("@p_PersonID", SqlDbType.Int).Value = "754381";
mysqlConnection.Open();
mySqlcmd.ExecuteNonQuery();
mysqlConnection.Close();
7
  • Cast the 1 to a byte (mySqlcmd.Parameters.Add("@p_PhoneNumberTypeID", SqlDbType.TinyInt).Value = (byte) 1;). Let me know if it works and I'll write it up as an answer Commented Dec 25, 2020 at 1:26
  • post your stored proc. definition. You might have your param types the wrong way around.... Commented Dec 25, 2020 at 2:10
  • @Flydog57 - i did that and i get this error now. Commented Dec 25, 2020 at 2:17
  • "PhoneNumber_Insert expects parameter @PhoneNumberTypeId which was not supplied" mySqlcmd.Parameters.Add("@p_PhoneNumberTypeID", SqlDbType.TinyInt).Value= (byte)1; Commented Dec 25, 2020 at 2:20
  • mySqlcmd.Parameters.Add("@p_PersonID", SqlDbType.Int).Value = "754381"; Why are you passing this as a string? Commented Dec 25, 2020 at 4:12

1 Answer 1

2

You're encountering bug 101302 in MySQL Connector/NET. There are three possible workarounds:

  1. Change your code to explicitly use MySqlDbType.Byte: mySqlcmd.Parameters.Add("@p_PhoneNumberTypeID", MySqlDbType.Byte).Value = 1;
  2. Downgrade to MySql.Data 8.0.21.
  3. Switch to MySqlConnector, which supports the same API as MySql.Data but is less buggy.
Sign up to request clarification or add additional context in comments.

1 Comment

@MitchWheat It's a problem that happens with various data types; see the duplicated bug report: bugs.mysql.com/bug.php?id=101424. That bug report just provided reproduction steps for BOOL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.