Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 15th, 2012, 02:04 AM
blueflash999 blueflash999 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 blueflash999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 55 sec
Reputation Power: 0
Select from help

My apologies for what mus be a very simple query but I can't find an answer as I'm not sure how to frame the qestion.
But in a program I have:

inputFile="c:\test\test.asc"

I want to put this variable into a select query:

"select * from inputFile"
but I can't get the syntax right.
if I put "select * from test.asc"
there no problem.

Can someone put me straight pleasse?
Thanks

Reply With Quote
  #2  
Old October 15th, 2012, 03:52 AM
willr willr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 10 willr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 2 m 42 sec
Reputation Power: 0
I'm not sure if I understand your problem entirely, but here are my thoughts:

FROM should be the table name

e.g.

SELECT column_name(s)
FROM table_name

SELECT * FROM (table name goes here)
WHERE (column name here)=inputFile

Hope that helps!

Reply With Quote
  #3  
Old October 15th, 2012, 04:26 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 16 sec
Reputation Power: 4140
Quote:
Originally Posted by blueflash999
But in a program I have:

inputFile="c:\test\test.asc"
what is this? a file or a table?

and what language are you using? php?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old October 15th, 2012, 06:06 AM
blueflash999 blueflash999 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 blueflash999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 55 sec
Reputation Power: 0
Sorry, I should have given more information. I am using vb6 and here is the relevant piece of code

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cm As ADODB.Command

Set conn = New ADODB.Connection
conn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & ";" & _
"Extended Properties=""text;HDR=No;FMT=Delimited( )"""
inputFile = "C:\test data\test data.asc"
Set cm = New ADODB.Command
cm.ActiveConnection = conn
cm.CommandType = adCmdText
cm.CommandText = "SELECT * FROM inputFile "
Set rs = New ADODB.Recordset

This code gives and error at the "set rs...." line because the object inputFile.txt cannot be found.

This code does not give an error

cm.CommandText = "SELECT * FROM C:\test data\test data.asc "


When the code is finished, the user will input the path to inputFile via a textbox on a form so I don't want to have to put the specific filename and path in the SELECT command.

Thanks for your help

Reply With Quote
  #5  
Old October 15th, 2012, 06:25 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 16 sec
Reputation Power: 4140
thread moved to visual basic forum

Reply With Quote
  #6  
Old October 15th, 2012, 10:57 AM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,938 medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)  Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Months 2 Weeks 2 Days 26 m 49 sec
Reputation Power: 8490
Facebook
Code:
cm.CommandText = "SELECT * FROM inputFile "


->

Code:
cm.CommandText = "SELECT * FROM " & inputFile 
__________________
medialint.com

“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

Reply With Quote
  #7  
Old October 15th, 2012, 02:12 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 167 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 26 m 18 sec
Reputation Power: 43
You may find the following sub routine useful. vKeys contains the SQL command string. The routine returns True if successful, and False if not with vExceptions containing the error. The recordset is opened, updated, and then closed.

J.A. Coutts
Code:
Public Function PutLocalData(vKeys As Variant, _
   vExceptions As Variant) As Boolean
' Purpose:
'   Passed SQL parameters in vKeys, save results.
' =====================================================
    Dim sErr As String
    Dim sSQL As String
    Dim cmdSQL As ADODB.Command
    Dim SnapData As New ADODB.Recordset
    Const sProc As String = "PutLocalData"
    On Error GoTo putDataErr
    Set cmdSQL = New ADODB.Command
    Set cmdSQL.ActiveConnection = adoConn1
    cmdSQL.CommandText = vKeys
    cmdSQL.Execute
    PutLocalData = True
Exit Function

putDataErr:
    sErr = msModule & gsDelimiter & sProc _
        & gsDelimiter & err.Number & gsDelimiter & err.Description
    Call LogError(sErr)
    vExceptions = sErr
End Function

Reply With Quote
  #8  
Old October 15th, 2012, 04:45 PM
blueflash999 blueflash999 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 blueflash999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 55 sec
Reputation Power: 0
If I use
cm.CommandText = "SELECT * FROM " & inputFile

I get a 'Syntax error in FROM clause'

when I try to execute the statement

rs.Open cm, , adOpenKeyset, adLockOptimistic

which follows the

Set rs = New ADODB.Recordset

statement

Reply With Quote
  #9  
Old October 16th, 2012, 12:46 AM
blueflash999 blueflash999 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 blueflash999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 55 sec
Reputation Power: 0
I have found the cause of the problem I think.
If the variable inputFile contains a path or filename with no spaces in it such as
"C:\testdata\testdata.asc"
everything works fine but if there are embedded spaces such as

"C:\test data\test data.asc"

then I get the Syntax in FROM statement error.

So is there any way of including the inputFile string which contains embedded spaces in the SELECT statement?

Reply With Quote
  #10  
Old October 16th, 2012, 01:51 AM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 167 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 26 m 18 sec
Reputation Power: 43
Quote:
Originally Posted by blueflash999
I have found the cause of the problem I think.
If the variable inputFile contains a path or filename with no spaces in it such as
"C:\testdata\testdata.asc"
everything works fine but if there are embedded spaces such as

"C:\test data\test data.asc"

then I get the Syntax in FROM statement error.

So is there any way of including the inputFile string which contains embedded spaces in the SELECT statement?

Spaces are often considered a separator in windows. Simply look at the links to any of the programs in the "Program Files" directory, and you will see they are enclosed in quotes. You can try single quotes:
cm.CommandText = "SELECT * FROM '" & inputFile & "'"

If that doesn't work, you can try quad quotes """".

J.A. Coutts

Reply With Quote
  #11  
Old October 16th, 2012, 02:10 AM
blueflash999 blueflash999 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 blueflash999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 55 sec
Reputation Power: 0
I am at a loss here.
I have been trying to get the select statement right by inputting the path directly:
"SELECT * FROM "c:\test data\test data.asc""

and varying the number of double quotes and single quotes around the path.
I either get a "syntax error in FROM clause" or
"Expected end of statement"
depending on the number and combination of quotes and spaces.

Reply With Quote
  #12  
Old October 16th, 2012, 07:30 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,239 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 15 h 17 m
Reputation Power: 4445
You're using the Jet drivers which are for Access databases. In Access SQL (and pretty much all sql) you don't select anything from a file name, you select records from tables or views.

Spend some time with the Jet ADO documentation it's somewhere in the msdn library online. There are numerous example codes that might help you understand how things are supposed to work.
Comments on this post
medialint agrees!
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Select from help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap