# char in field name causing error

  • Thread starter Thread starter CSharpner
  • Start date Start date
C

CSharpner

I'm using DB2 for my database server. I'm trying to configure a
DataAtapter, but after selecting the fields I need, I get the error,
"unable to parse query text". I know that the cause is a field name
with the # (pound character) in the name, like "Part#".

Changing the field name is, unfortunately, not an option. How the
heck are you supposed to query a table like that?

TIA
 
TIA,

If you are using an AS400 system (DB2) like I am, here is a sample SELECT
string from one of my apps:

SELECT CMNAME, CMADR1, CMCITY, CMST, CMZIP5, CMPHON, "CMCUS#", CMMAGC,
CMADR2, CMCONT, CMFAX
FROM QS36F.ARCUST
WHERE ("CMCUS#" = ?)

As you can see the field with the pound sign (#) is surrounded with
quotation marks. Now, this select statement was generated by the Command
Wizard.

Hope this helps.

Brad
 
<<<<
How the heck are you supposed to query a table like that?
Design the DB correctly to begin with? :>)

Fieldnames should never contain anything but alpha-numeric values & the
underscore character. Even the numeric can be dicey.

However, since you can't unshoot the gun, wrap the field name in [] -
[Part#] - in your queries.

Bob Lehmann
 
Thanks! I knew it had to be something simple like that!.

Miha Markic said:
Did you try to put the field in square brackets?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

CSharpner said:
I'm using DB2 for my database server. I'm trying to configure a
DataAtapter, but after selecting the fields I need, I get the error,
"unable to parse query text". I know that the cause is a field name
with the # (pound character) in the name, like "Part#".

Changing the field name is, unfortunately, not an option. How the
heck are you supposed to query a table like that?

TIA
 
Thanks!

Brad Allison said:
TIA,

If you are using an AS400 system (DB2) like I am, here is a sample SELECT
string from one of my apps:

SELECT CMNAME, CMADR1, CMCITY, CMST, CMZIP5, CMPHON, "CMCUS#", CMMAGC,
CMADR2, CMCONT, CMFAX
FROM QS36F.ARCUST
WHERE ("CMCUS#" = ?)

As you can see the field with the pound sign (#) is surrounded with
quotation marks. Now, this select statement was generated by the Command
Wizard.

Hope this helps.

Brad
 
Bob Lehmann said:
<<<<
How the heck are you supposed to query a table like that?

Design the DB correctly to begin with? :>)

Fieldnames should never contain anything but alpha-numeric values & the
underscore character. Even the numeric can be dicey.

Trust me! If I had any say so, there'd be quite a few differences! :)
I can safely wash my hands of any responsibility in that department.
However, since you can't unshoot the gun, wrap the field name in [] -
[Part#] - in your queries.

Thanks Bob!
 
Back
Top