Board index » Visual Studio » Response.Write Text with DataField

Response.Write Text with DataField

Visual Studio61
Can someone please shed some light as to why this will not work

properly:



<%

If (News.Fields.Item("Chart").Value) = "" Then

Response.Write "Not Available"

Else

Response.Write "<img src='" &

News.Fields.Item("Chart").Value & "'>"

End If

%>



The check works fine...even the first response.write works... but the

second response.write never inserts the database field information. I

have 3 sets of data in the database, the first and last have data in

the "Chart" field (data in field = test), the second is empty. Here is

what I get:



<img src=''>

Not Available

<img src=''>


-
 

Re:Response.Write Text with DataField

Hi,



This problem used to accure with me, until i started retriving data from

the database in an other way;

instead of

News.Fields.Item("Chart").Value

use

News.Fields("Chart")



if it didnt work, remove any "On Error resume next" from ur code

and if didnt work, open the Query in the database and check if it does

show any records, if not that means that u have an error in ur Query

Statement



and if it showed that everything is working fine,

put this code inside ur page:



do until News.EOF

response.write News.Fields("Chart") & "<BR>"

News.MoveNext

Loop



This way u make sure 100% that ur data is neing retrieved correctly



Hope it works,

Please tell me what happens with u,



Best Regards

Firas S Assaad

0096892166434

firas489@gmail.com

ASP/VBscript Developer





*** Sent via Developersdex www.developersdex.com">www.developersdex.com ***

-

Re:Response.Write Text with DataField

Thanks for the advice. I tried all that you said, with no luck.

However, here is what I attempted and it worked (somewhat anyways).



<%

Response.Write "<img src='" &

News.Fields("Chart").Value & "'>"

%>



As you can see, I removed the If statement and left the last write in.

It worked. I put the If statement back in and it quit working. Any

ideas?



-

Re:Response.Write Text with DataField

It appears that the IF statement is causing the problem. I changed the

code to this:

<img src="<%

If (News.Fields("Chart")) <>"" Then

Response.Write News.Fields("Chart") & "..."

Else

Response.Write ".\imgs\nochart.jpg"

End If

%>" />



Now on records 1 and 3, the output is: <img src="..." />



Strange that it is dropping the datafield yet the IF check is working

properly.



-

Re:Response.Write Text with DataField







I Have been thinking about it lately, and i had an idea, which most of

the times works.



Change your Query, so that it will only retrieve the records that Chart

Field doesnt equal to nothing



It will look something like that



"SELECT * FROM table WHERE Chart is not null"





Hope this works,

Tell what happens







Best Regards

Firas S Assaad

0096892166434

firas489@gmail.com

ASP/VBscript Developer





*** Sent via Developersdex www.developersdex.com">www.developersdex.com ***

-