none
ERROR [42000] [Sybase][ODBC Driver][Adaptive Server Enterprise]Implicit conversion RRS feed

  • Question

  • ERROR [42000] [Sybase][ODBC Driver][Adaptive Server Enterprise]Implicit conversion from datatype 'VARCHAR' to 'SMALLINT' is not allowed.  Use the CONVERT function to run this query.

    See below code: Field1 is smallint, Field3 is varchar(255), there is nothing more, why so many error 42000? However, there are some other fields in the table: 

    • Field1: smallint
    • Field2: varchar(255)
    • Field3: varchar(255)
    • Field4: char(2)
    • Field5: smallint
    • Field6: tinyint
    • Field7: smallint


    Thanks.

     OdbcConnection Cn = new OdbcConnection("ConnectionString");
                Cn.Open();
                string Query = "SELECT 'Field1(' + Field1 + ') : ' + Field3 As ComboBoxDisplayItem FROM TableName";
                OdbcCommand cmd = new OdbcCommand(Query, Cn);
                OdbcDataReader dr = cmd.ExecuteReader();

    Monday, March 18, 2019 12:40 PM

Answers

All replies

  • It seems to me that you should be posting to a Sybase forum and not to the C# forum about your issues. 
    Monday, March 18, 2019 1:01 PM
  • The error is in your SELECT statement and the data in the database. The query is trying to take a VARCHAR (string) and convert it to a SMALLINT (number) and it isn't going to work. You need to copy your query and put it into your dabase management tool to determine where the problem is. Once you've fixed the query such that your DB is happy you can put it back into C# and try again.

    My running theory is that Field1 or Field3 is a SMALLINT so you're trying to concat strings to an integral value and the DB doesn't like it. As the error says, use CONVERT to convert the integral column to a string and then do the concat. Your DB tool should help you with this syntax.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, March 18, 2019 3:17 PM
    Moderator
  • Problem solved earlier, by using SQL CAST function.

    Thanks.

    • Marked as answer by VA_er Tuesday, March 19, 2019 3:25 AM
    Monday, March 18, 2019 3:26 PM
  • Hi

    It seems that your problem has been solved. If so, please post "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Jack

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 19, 2019 3:13 AM
    Moderator