"freddy" <fr****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
I have a select statement like this:
string Select = "Select TableofContents, DataOwner, Delegates From NYC";
and it work fine, but if I was to put a space in like this:
string Select = "Select Table of Contents, Data Owner, Delegates From
NYC";
I would get an error in my da.fill(ds);
Why can I not use a space in my select statement. I have to connect to a
db, but I can not change it.
The short answer is that the names in your query must match the table and
field names defined in the database.
You cannot decide to introduce spaces in the names when you write the query.
What database are you using?
I believe the question is whether or not the database you are querying
allows spaces in table and field names.
The solution of enclosing the name in [] if there are spaces works OK in an
Access database, but many databases will not permit spaces in names.
Jared's response indicating use of [] should work in an Access database if
you have filed defined in the NYC table with names "Table of Contents" "Data
Owner" and "Delegates".
Freddy's response to Jared that his solution did not work is probably based
on the fact that Jared placed [] around only one of the two field names that
contain embedded spaces.
OTOH, Oracle would not have permitted field names with embedded spaces in
the first place.
IMHO, using table and field names with embedded spaces (even if permitted by
the DBMS) is a poor practice that will end up causing far more trouble than
it saves.
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.