Bug #10065 <X>int types can't be cast to string
Submitted: 21 Apr 2005 16:33 Modified: 18 Jun 2005 11:08
Reporter: Mickael Besson Email Updates:
Status: No Feedback Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.4 & MySQL 4.1.8 OS:Microsoft Windows (Windows XP (.NET) & NT4 (MySQL))
Assigned to: CPU Architecture:Any

[21 Apr 2005 16:33] Mickael Besson
I must migrate a web ASP.NET application from Oracle to MySQL.

In fact, the program make a connection to a MySQL database, and recover rows with a "Select" request :

            'Initialize the request
            l_s_sql = "SELECT " + p_s_table + "_CODE, " + p_s_table + "_NOM" _
                + " FROM CNL_" + p_s_table _
                + " WHERE " + p_s_table + "_USER = ?"
            l_o_dr = RetourneDR(l_o_cn, l_s_sql, UserName)
            'load submenu
            While l_o_dr.Read
                If Not l_b_menu Then
                    Menu.Add("Mes recherches", MenuLevel.Sub)
                    l_b_menu = True
                End If
                Menu.Add(CStr(Nz(l_o_dr.Item(1))), MenuLevel.SubSub, p_s_url + CStr(Nz(l_o_dr.Item(0))))

            End While
        Catch ex As Exception
        End Try
There's a bug I found when I compiled :
"Cast from type 'UInt16' to type 'String' is not valid."

PB HERE :CStr(Nz(l_o_dr.Item(0)))
-> Item(0) corresponds to the primary key of the table and has got the type 'SmallInt'
When I change its type to INTEGER on MySQL server, the cast function don't crash...

Is it normal ?

For information :

    Public Function Nz(ByVal p_o_val As Object, _
     Optional ByVal p_o_default As Object = Nothing) As Object

        If IsDBNull(p_o_val) Then
            Return p_o_default
            Return p_o_val
        End If
    End Function

How to repeat:
all is above

Suggested fix:
[18 May 2005 11:08] Vasily Kishkin
I tried to repeat. I created table with smallint field and test case for checking. Probably I misunderstood you. But my test case works fine. I attached it to Files.
Could you look and correct my code ? Otherwise I can't repeat this bug. Thanks.
[18 May 2005 11:09] Vasily Kishkin
Test case

Attachment: 10065.zip (application/x-zip-compressed, text), 3.04 KiB.

[18 Jun 2005 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".