The forum will be down for maintenance at some point between Friday, September 25, 2020 at 5pm PDT and Sunday, September 27, 2020 at 11:59 PDT. Downtime is unknown but will be minimized.

Trying to link Visual Studio C# project combo box to Sybase database. The error pops up when I run the Visual Studio C# code.

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


Error Sceenshot:

OdbcConnection Cn = new OdbcConnection("ConnectionString");


string Query = "SELECT 'Field1(' + Field1 + ') : ' + Field3 As ComboBoxDisplayItem FROM TableName";

OdbcCommand cmd = new OdbcCommand(Query, Cn);

OdbcDataReader dr = cmd.ExecuteReader();

asked 18 Mar '19, 10:16

VAer's gravatar image

accept rate: 0%

edited 18 Mar '19, 10:26

> Adaptive Server Enterprise

This is a forum for SQL Anywhere, previously known as Adaptive Server Anywhere, which is vastly different from Adaptive Server Enterprise.

permanent link

answered 18 Mar '19, 10:24

Breck%20Carter's gravatar image

Breck Carter
accept rate: 20%

It looks like you are using Adaptive Server Enterprise (ASE). This forum is for SQLAnywhere.

permanent link

answered 18 Mar '19, 10:24

John%20Smirnios's gravatar image

John Smirnios
accept rate: 38%

The problem how to fix my query? Thanks.

(18 Mar '19, 10:27) VAer
Replies hidden

Well, I don't know ASE semantics since that's a whole other database product but it would seem that you build a query such as:

SELECT 'Field1(' + Field1 + ') : ' + Field3 As ComboBoxDisplayItem FROM TableName

So, you have an expression which is varchar + smallint + varchar + varchar(255). The first operand is a varchar with the value 'Field1(' The second operand is a smallint is the value of Field1 from a given row etc.

So, either all operands need to go to strings and be concatenated (assuming ASE supports '+' as a concatenation operator -- not sure) or they need to all go to smallint and be added arithmetically. I'm guessing ASE is doing the latter and trying to convert the string 'Field1(' to a smallint. It's also trying to convert '): ' to a smallint. The question is... what are you actually trying to accomplish? I'm guessing you want all strings? If so, try using CAST() (if ASE supports it) or Convert() to cast Field3 to a varchar.

(18 Mar '19, 10:46) John Smirnios
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 18 Mar '19, 10:16

question was seen: 1,126 times

last updated: 18 Mar '19, 10:46