Classic ASP DatabasesDiscuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
CODE BELOW
Someone give me some more eyes to see what I am screwing up. I have done 1000 of these but this one doesn't work properly... Here is the scenario. I am pulling field data from an access db. When there is data in the fields (MEMO field type due to size) the information from each field is displayed on web page as coded after each ELSE statement. But when there is no data in field (I delete it) then nothing is displayed on the page but the beginning of the wrong outputted text (Your company contact is: NOTHING HERE , as in first IF THEN statement).
I have already tried replacing the "" with NULL in the IF statement and also tried to use ... IF ISEMPTY(txtCompanyContact) THEN ... but identical result. I want to give the user a reminder if this info has not been completed or display it if it is already in the db. Does the memo field type effect this? Is NULL or "" not appropriate for checking for existing data in a field? I know the db connection and vars are working because the vars txtCompanyContact, etc. are displayed if they exist in db. But if DB is empty then it displays the second message after ELSE incompletely (Your company contact is: ______ )
Sorry for the lengthy explanation - appreciate any advice...
IF txtCompanyContact = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site contact is: <strong>" & txtCompanyContact & "</strong><BR>"
END IF
IF txtSitePhone = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site phone is: <strong>" & txtSitePhone & "</strong><BR>"
END IF
IF txtSiteEmail = "" THEN
response.write "You have not yet completed your public information profile."
ELSE
response.write "" & _
"Your site e-mail is: <strong>" & txtSiteEmail & "</strong><BR>"
END IF
Are you sure this isn't caused by Access's "spaces for empty fields" feature? Often an apparently empty field contains a space.
Here's what you can try:
If Trim(txtCompanyContact) & "" = "" Then
Response.Write "You have not yet completed your public information profile."
Else
Response.Write "" & _
"Your site contact is: <strong>" & _
txtCompanyContact & "</strong><BR>"
End If
How do you assign txtCompanyContact a value? Are you sure it contains the right info from the database??
Dim txtCompanyContact
txtCompanyContact = objRS("txtCompanyContact")
after creating a dsn connection. I knew it was working because when the field had a name it appeared on the page -
Your contact name is : NAME HERE
But when the field was empty the page would just display
Your contact name is:
I did what you said and understand the trim function and it worked great, sincere thanks. But one last question. I have used trim but dont quite understand the method/syntax you used.
If Trim(txtCompanyContact) & "" = "" Then
What is concatenated with the '&'... and "" ...?
I will try to figure it out but thanks very much, it works now...
If txtCompanyContact contains a NULL value, then you can't compare it to a zero-length-string: "" and still return True. Imar is doing an implicit conversion of the NULL value to a zero-length-string by appending a ZLS to the possible NULL value. Then when you compare it to another ZLS, you will get True.