Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2005, 12:26 PM
Registered User
 
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO Data Control

Greetings!

The problem I am having seems like it should be a simple task. However, I am not making much progress with it at all. I am using an ADO
Data control on my form to connect to an AS/400. When I set its Record source equal to a SQL statement it works fine if it is a non-text column I am querying against. For example, if I state:

    Adodc1.RecordSource = "select * from chgtracker where chgdate = " & prmTest
    Where prmTest is a string containing 20050114

Then all works well.

However, if the table column I am searching against contains text/string data I get an error. For example:

Adodc1.RecordSource="select * from chgtracker where approveby = " & prmTest2

Where prmTest2 is a string containing the literal “TESTER” (including quotes as seen in debug) and Approveby is a field containing string data, I get an error stating that “The column TESTER does not exist in the specified tables”.
I am not sure why this is taking place or why the quotes have been stripped off but the need to get past this is high. Thanks for your help!!!

Chris


 
Old April 5th, 2005, 08:24 AM
Authorized User
 
Join Date: Jul 2004
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know why the first one is working, but each should be contained in SINGLE quotes IE '20050114' or 'tester'

Double quotes are a VB string thing

In debug your source string should look like

select * from chgtracker where approveby = 'tester'
or
select * from chgtracker where approveby = '20050114'





 
Old April 5th, 2005, 11:58 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

It is helpfull to think about what your statements will evaluate to.
If prmTest = 45 and prmTest2 = "Dilly", then your first statement evaluates to
Code:
    select * from chgtracker where chgdate = 45
Your second statement evaluates to
Code:
    select * from chgtracker where approveby = Dilly
In that case, Dilly would be initially thought to be a field/column, and if that could not be resolved it would be evaluated as a variable, since Dilly is not really a value.

dhay1999 is mistaken regarding the first statement. A string of digits is regarded as a literal value. Enclosing that in quotes would result in failure to fly.

But he is right regarding the second statement. When the value on one side of an equality operator is a literal string, it needs to have a single quote on each side of the characters. Your statement should be
Code:
    Adodc1.RecordSource="select * from chgtracker where approveby = '" & prmTest2 & "'"
or the contents of prmTest2 should be like 'Dilly'





Similar Threads
Thread Thread Starter Forum Replies Last Post
ADO Data Control Thurston VB.NET 2002/2003 Basics 3 December 6th, 2005 10:38 PM
ADO Data Control jwilkerson VB Databases Basics 1 September 29th, 2004 10:53 AM
pls hlp!!! Microsoft ADO Data Control not found x2c4u VB Databases Basics 3 September 29th, 2004 09:42 AM
ADO Data Control jwilkerson Beginning VB 6 1 October 21st, 2003 06:30 AM
ADO Data Control fordrs3 Beginning VB 6 3 June 17th, 2003 04:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.