Find length of field from database table
Find length of field from database table
am 25.01.2007 08:47:25 von 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....
Re: Find length of field from database table
am 25.01.2007 11:25:58 von reb01501
SSG wrote:
> 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!
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Re: Find length of field from database table
am 02.02.2007 06:37:36 von Roland Hall
"SSG" wrote in message
news:1169711245.150386.312860@q2g2000cwa.googlegroups.com...
> 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
--
Roland Hall