Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

error converting the varchar value 'True' to a column of d..

 
   Database Help (Home) -> Visual Basic -> ADO RSS
Next:  base64 {en,de}code mysql  
Author Message
dk10

External


Since: Sep 08, 2004
Posts: 2



(Msg. 1) Posted: Tue Feb 08, 2005 12:11 pm
Post subject: error converting the varchar value 'True' to a column of dat
Archived from groups: microsoft>public>vb>database>ado (more info?)

In a vb6 app using ado connecting to a sql server 2000 stored procedure,
am seeing this error:
"Syntax error converting the varchar value 'True' to a column of data
smallint"

The error only seems to happen when updating one record. Other
records work fine. The stored proc takes 22 varchar parameters, 1 smallint
parameter,
and one int parameter

Is this indicating a problem with the varchar parameters or the smallint
parameter?

any ideas?

Thanks,
dk

 >> Stay informed about: error converting the varchar value 'True' to a column of d.. 
Back to top
Login to vote
Mark J. McGinty

External


Since: Aug 31, 2003
Posts: 30



(Msg. 2) Posted: Mon Feb 14, 2005 5:40 am
Post subject: Re: error converting the varchar value 'True' to a column of [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"dk" <dk.TakeThisOut@discussions.microsoft.com> wrote in message
news:3F3A0B54-B4DA-4806-9E6C-6535BAB4D78D@microsoft.com...
 > In a vb6 app using ado connecting to a sql server 2000 stored procedure,
 > am seeing this error:
 > "Syntax error converting the varchar value 'True' to a column of data
 > smallint"
 >
 > The error only seems to happen when updating one record. Other
 > records work fine. The stored proc takes 22 varchar parameters, 1 smallint
 > parameter,
 > and one int parameter
 >
 > Is this indicating a problem with the varchar parameters or the smallint
 > parameter?
 >
 > any ideas?

The value True (in VB) will implicitly convert to any integer type, because
it's literally represented as -1. The string "True" (in VB) can be coersed
to the value True (in VB) using
CBool(variable_that_resolves_to_string_true).

Afaik, there is no symbolic value TRUE in SQL, the Boolean concept exists,
expressions evaluate as true or false, but there are no symbolic constants
that represents boolean values. Try this in Query Analyzer:

if TRUE
print 'in truth there is meaning' --(Returns a syntax error.) Otoh,
this:

if (1 = 1)
print 'in truth there may be meaning' --(Prints text as expected, 1 = 1
is a true expression.)

As such, the non-numeric string 'True' cannot be converted to an integer in
T-SQL, except perhaps with a case statement in the expression, e.g., CASE
WHEN @param = 'True' THEN 1 ELSE 0 END (but that doesn't really count.)

So, to answer your question directly, the problem is that non-numeric string
values are being passed in varchar parameters that are intended for
conversion to interger field values. What is likely happening is that a
Boolean variable (or variant/vt_boolean) is being implicitly or explicitly
converted to a string (the result of which is the string 'True'.) You must
make sure that any VB boolean values are explicitly coersed to their numeric
equivilents before passing to SQL, e.g.,

Dim b as Boolean
Dim p as ADODB.Parameter ' Value property is of type variant
[skipping init]
p.Value = CStr(CInt(b))

If you merely coerse to an integer type, ADO will whine about type mismatch.
If you merely assign p.Value = b, or do something less sophisticated like:

Dim s as String
s = b
p.Value = s ' this, btw, would be a kludge

you'll end-up with the string value 'True' on the SQL side, which as you've
observed, is problematic.


Hope this helps,
Mark


 > Thanks,
 > dk
 ><!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: error converting the varchar value 'True' to a column of d.. 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Visual Basic -> ADO All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]