473,770 Members | 4,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Printing a field with a hyphen in ?

Hi,

I have a field in a select query: 'Metal-XS' which is causing a problem
The recordset should look like: RS2("Metal-XS") but it says this does
not exist, and I cannot get the SQL to work in ASP when I add this
field. Is there any code way around this, or should I edit the db and
change/create a new field ?

Thanks

David

Sep 25 '06 #1
9 1814
"David" <da*********@sc ene-double.co.ukwro te in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi,

I have a field in a select query: 'Metal-XS' which is causing a problem
The recordset should look like: RS2("Metal-XS") but it says this does
not exist, and I cannot get the SQL to work in ASP when I add this
field. Is there any code way around this, or should I edit the db and
change/create a new field ?
Don't know why a hyphenated field name fails.

Try enclosing it in brackets -- as is needed for reserved words:

RS2("[Metal-XS]").Value

Or maybe it just wants ".Value"...
Sep 25 '06 #2
David wrote:
Hi,

I have a field in a select query: 'Metal-XS' which is causing a
problem The recordset should look like: RS2("Metal-XS") but it says
this does not exist, and I cannot get the SQL to work in ASP when I
add this field. Is there any code way around this, or should I edit
the db and change/create a new field ?
I would recommend the latter. Nonstandard characters should definitely
be avoided*, and if you have the opportunity to eliminate them, you
should take it.
If you can't do this for some reason, you will need to remember to
surround the field name with brackets [] when referencing it in a query
run via ADO.
* Also, reserved keywords should be avoided:
http://www.aspfaq.com/show.asp?id=2080
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 25 '06 #3
McKirahan wrote:
Don't know why a hyphenated field name fails.

Try enclosing it in brackets -- as is needed for reserved words:

RS2("[Metal-XS]").Value
That suggestion will definitely cause an error with the MSSQL OLE DB
provider. If the SELECT statement looks anything like this...

SELECT [Metal-XS] FROM ...

....then the correct way to read the value is:

RS2.Fields("Met al-XS").Value

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 25 '06 #4
Bob Barrows [MVP] wrote:
Nonstandard characters should definitely be avoided*, and
if you have the opportunity to eliminate them, you should
take it.
Why do you say that, Bob? For that matter, how do you define "nonstandar d"?
According to this, there exist rules that dictate when delimiting is
required:

http://msdn.microsoft.com/library/en...on_03_6e9e.asp

But if delimited identifiers are acceptible to SQL Server, what demands that
they *definitely* be avoided?

There was a time when I might have said the same, but after the first time I
needed to deal with delimited identifiers (a vendor-supplied DB, of course),
it became -- for me -- a solved problem, and it only took a minute to
understand the concept. So what's the big deal?


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 25 '06 #5
Dave Anderson wrote:
Bob Barrows [MVP] wrote:
>Nonstandard characters should definitely be avoided*, and
if you have the opportunity to eliminate them, you should
take it.

Why do you say that, Bob? For that matter, how do you define
"nonstandar d"?
This is defined in the article you cite below. See "Rules for Regular
Identifiers"
According to this, there exist rules that dictate when
delimiting is required:

http://msdn.microsoft.com/library/en...on_03_6e9e.asp

But if delimited identifiers are acceptible to SQL Server, what
demands that they *definitely* be avoided?
I should have said "in my opinion" (but I'm definitely not alone in that
opinion). Just because the rdbms provides a way for those characters to
be handled does not mean one should make it handle them (not that this
is creating any kind of overhead for the dbms - I'm not saying that).

I hate having to remember to use the brackets in special cases so I
avoid creating situations requiring their use. If I used brackets for
all object names, regular and irregular, then it would not be such a big
deal for me, I admit.
>
There was a time when I might have said the same, but after the first
time I needed to deal with delimited identifiers (a vendor-supplied
DB, of course), it became -- for me -- a solved problem, and it only
took a minute to understand the concept. So what's the big deal?
Yes, I've had to deal with vendor-supplied and legacy databases, and
cursed the creators every time I had to type a delimiter. I like to use
RapidSQL, which has a nice code generator. Unfortunately, that code
generator does not delimit object names, so I wind up having to go in
and insert delimiters where necessary.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 25 '06 #6
replace the name with the numerical position equivalent such as

RS2(0)

to see if it is the name causing the problem or if your query is faulty

"David" <da*********@sc ene-double.co.ukwro te in message news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi,

I have a field in a select query: 'Metal-XS' which is causing a problem
The recordset should look like: RS2("Metal-XS") but it says this does
not exist, and I cannot get the SQL to work in ASP when I add this
field. Is there any code way around this, or should I edit the db and
change/create a new field ?

Thanks

David

Sep 25 '06 #7
But if delimited identifiers are acceptible to SQL Server, what demands
that they *definitely* be avoided?
Because they are a P.I.T.A. to everyone who has to remember when to put
square brackets around a name.

Also, there are bugs in SQL Server, e.g. many of the internal procedures for
iterating through databases will fail if there is a dash in the name,
because the name is not always properly delimited. If Microsoft can forget
to bullet-proof code, so can the rest of us.
There was a time when I might have said the same, but after the first time
I needed to deal with delimited identifiers (a vendor-supplied DB, of
course), it became -- for me -- a solved problem, and it only took a
minute to understand the concept. So what's the big deal?
The range of expertise for accessing a database will vary -- maybe you are
very smart compared to the next guy who will work on your system. Why force
delimiters when you don't need to? This seems like putting kilometers
instead of miles on the speedometers of US-based vehicles because the math
is easy and everyone else in the world is using metric. While and having
grown up in Canada this wouldn't be a problem for me, I can certainly
envision the /*avoidable*/ chaos.

What makes the alternative (leaving the column name as is, and requiring
delimiters) so desirable?

A
Sep 25 '06 #8
Bob Barrows [MVP] wrote:
Dave Anderson wrote:
>Bob Barrows [MVP] wrote:
>>Nonstandard characters should definitely be avoided*, and
if you have the opportunity to eliminate them, you should
take it.

Why do you say that, Bob? For that matter, how do you define
"nonstandard "?

This is defined in the article you cite below. See "Rules for Regular
Identifiers"
I should have said that I tend to define this standard a little more
strictly. I doubt you will find an object name containing anything but
aA-zZ in any database I create. I will use underscores, but not for
objects that will be used in sql statements (constraint names, idex
names, etc.)

But this is just my prejudice. I'm not sure what lead me in that
direction. Maybe it was the first time I had a VB function bomb due to
the absence of delimiters in a sql statement (back when I was using
dynamic sql).

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 25 '06 #9
Aaron Bertrand [SQL Server MVP] wrote:
Also, there are bugs in SQL Server, e.g. many of the
internal procedures for iterating through databases
will fail if there is a dash in the name, because the
name is not always properly delimited.
I did not know this. I was under the impression that SQL Server uses the
internal identifiers [id column in sysobjects] for internal processes.
...Why force delimiters when you don't need to?
I generally don't. But I wouldn't be afraid to use them if I felt there were
a good reason to do so. More to the point, I do not care when someone else
does, and I certainly wouldn't admonish them for doing so. In my opinion, it
is no different than dealing with case sensitivity in JScript or having to
Dim your variables with Option Explicit in VBScript.
...What makes the alternative (leaving the column name
as is, and requiring delimiters) so desirable?
Well, that's a good question. Why would case sensitivity in JScript be
desirable when the alternative is "easier"? Why would
document.getEle mentById() be desirable when document.all[] is "easier"? Why
does Rice play Texas[1]?

[1] Kennedy's answer to his own rhetorical question is quite relevant here.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Sep 25 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
31424
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody somewhere said: Alternately, you can use CSS to declare a class having: ..nowrap { white-space:nowrap } .... and then wrap the compound word in a <span class=nowrap></span> tag (or any other suitable inline tag). You can also try {...
13
49888
by: Matt | last post by:
I would like to set the "list-style-type" to be a hyphen (-). How can I accomplish this in a style sheet. I tried list-style-type: hyphen; and list-style-type: dash; but neither worked. I also tried adding this to the style sheet (with the list-style-type set to none in the UL element). LI:Before { content: "- "; }
22
8015
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a way to denote a hyphen in HTML, that the line can be broken after? I've read some stuff about soft hyphens and non-breaking hyphens, but those seem like the opposite of what I'm looking for. I want a normal hyphen, that always appears, and I...
14
5512
by: Larry R Harrison Jr | last post by:
I have designed databases but have never come across any complications due to the ridiculous situation of a hyphenated last name. As a database designer (very junior level) I disdain anything unwieldly, and consider this unwieldly. I haven't dealt with it, as I said, but I figure if I do, I'd simply design the text field to not accept hyphens, so Smith-Barney would be stored as SmithBarney, or even Smithbarney as I commonly have the...
7
12952
by: Tizzah | last post by:
What is wrong with that? regex = /^(http|https):\/\/+({1}+)*\.{2,5}(({1,5})?\/.*)?$/ if(field.hpage.value != regex.test(field.hpage.value)){ alert("Bad Homepage") field.hpage.focus() field.hpage.select() return false
1
2561
by: Curtis | last post by:
I am having a problem with the coding below that someone was trying to help me with in another website. I have been to several websites and hopefully here I can get it resolved. I inherited this database and issue, and I apologize for a bit lengthy. The coding is located in the Event Procedure on the "On Open" property of the {rptLetter}: Sub cmdPrint_Click() 'Check if no results in any field, if all missing 'inform user and exit...
4
4558
by: Rubin | last post by:
1) I want to show a breaking hyphen in Mozilla 1.5.0.4 How do I do that? "Unicode standard annex #14", <http://www.unicode.org/reports/tr14/>, defines 4 breaking hyphens. <quote> Breaking hyphens establish explicit break opportunities immediately after each occurrence.
6
7822
by: Kc-Mass | last post by:
In a standard Ascii table a dash or hyphen is decimal 45. A period or dot is decimal 46. If I sort a table or recordset of mixed character string ascending in Access, those strings beginning with a dot or period are first; those beginning with a dash or hyphen are sorted as though the hyphen is not there (that is the next non-hyphen character controls the sort order). Those that are alpha or numeric are sorted in their normal order...
2
1298
by: madval | last post by:
hi, i need your help, i'll receive some ms word documents (paragraphs, bullets, different fonts in a document -family-size-format, images, etc. a "normal" document) and i need to print them on a preprinted sheet that have 2 sections for printing data. +------------------------------------------+ | | | +----------------------------------+ | | | | | | | ...
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.