Find length of field from database table

S

SSG

In my database table , I have field to store the text,..

I am tryinf to find the length of the filed in ASP like below

response.write len(rs("cname1"))

It is displaying the value , when the data in the field is nonzero, it
is not displaying anything if the filed is mty in table..

I cant understand y it is displaying the length as 0 , bcaz i want to
compare the length , if the length is zero , it will display one result
or else it will display the value....
 
B

Bob Barrows [MVP]

SSG said:
In my database table ,

When asking a database-related question, even if you do not think it is
relevant you should always supply the type and version of the database you
are using. It is relevant more often tha nis commonly realized.
I have field to store the text,..

I am tryinf to find the length of the filed in ASP like below

response.write len(rs("cname1"))

It is displaying the value , when the data in the field is nonzero, it
is not displaying anything if the filed is mty in table..

Do you have error-trapping (on error resume next) enabled? If so, disable it
and see if your code is generating an "invalid use of Null" error. That
should be a clue to your problem. If your field is configured to accept
Null, then you are seeing the difference between Null and a zero-length
string.

You _could_ test the field for Null before attempting to get its length:

val = rs("cname1").value
if not isnull(val) then
response.write len(val)
else
response.write "0"
end if

But my preferred solution would be to modify the sql statement generating
the recordset to ensure than the field never contains Null. The details
about how to do this depend on what database type and version you are using
.... see? it is relevant even in this case!
 
R

Roland Hall

SSG said:
In my database table , I have field to store the text,..

I am tryinf to find the length of the filed in ASP like below

response.write len(rs("cname1"))

It is displaying the value , when the data in the field is nonzero, it
is not displaying anything if the filed is mty in table..

I cant understand y it is displaying the length as 0 , bcaz i want to
compare the length , if the length is zero , it will display one result
or else it will display the value....

Perhaps...

if rs("cname1") = "" then
Response.Write "Empty"
else
Response.Write rs("cname")
end if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,129
Messages
2,570,769
Members
47,325
Latest member
sloppy-dobby

Latest Threads

Top