By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 996 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Can't display image from mySQL database

P: 6
Query.asp
Expand|Select|Wrap|Line Numbers
  1. <%@ LANGUAGE="VBSCRIPT" %>
  2. <!-- #include file="../../includes/dbconn.asp"-->
  3. <%
  4. dim MyRs, sqlstr, MyConn
  5.  
  6.    Response.Expires = 0
  7.    Response.Buffer = TRUE
  8.    Response.Clear
  9.    Response.ContentType = "image/gif"
  10.  
  11.   Set MyConn = Server.CreateObject("ADODB.Connection")
  12.   MyConn.Open dbConn
  13.   Set MyRs = Server.CreateObject("ADODB.Recordset")
  14.  
  15.       sqlstr="select img from img"
  16.       MyRs.Open sqlstr, MyConn, adOpenKeyset, adLockOptimistic
  17.        Response.BinaryWrite MyRs("img")
  18.       Response.End
  19.  
  20. MyRs.Close
  21. MyConn.Close
  22.  
  23. set MyRs=nothing
  24. set MyConn= nothing
  25. %>
Main.asp
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.    <HEAD><TITLE>Display Image</TITLE></HEAD>
  3.    <BODY>
  4.    This page will display the image New Moon Books from a SQL Server
  5.    image field.<BR>
  6.    <IMG SRC="Query.ASP">
  7.    </BODY>
  8.    </HTML>
why can't display, really dunno what to do
Dec 2 '07 #1
Share this Question
Share on Google+
7 Replies


codegecko
Expert 100+
P: 533
Hi Alex,

Try changing the SQL query as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT [img].[img] FROM [img];
SQL does not like parent and child objects (the child/ren field/s of the parent table) to have identical names as it can confuse things.
The square brackets should act as field name delimiters so the first lot of text in square brackets identifies the table name, followed by the field name.

Failing that, rename the image binary data field to something different, for example ImgData and let us know how you get on.

You also were calling your SQL statement twice - using the Open command with a SQL string as a parameter automatically executes the SQL and returns the results. I removed the line where you used MyRs.Execute.

And finally, simple question - but do you have any image data stored in your database at present?

Best regards,

medicineworker
Dec 2 '07 #2

P: 6
Hi Alex,

Try changing the SQL query as follows:
Expand|Select|Wrap|Line Numbers
  1. SELECT [img].[img] FROM [img];
SQL does not like parent and child objects (the child/ren field/s of the parent table) to have identical names as it can confuse things.
The square brackets should act as field name delimiters so the first lot of text in square brackets identifies the table name, followed by the field name.

Failing that, rename the image binary data field to something different, for example ImgData and let us know how you get on.

You also were calling your SQL statement twice - using the Open command with a SQL string as a parameter automatically executes the SQL and returns the results. I removed the line where you used MyRs.Execute.

And finally, simple question - but do you have any image data stored in your database at present?

Best regards,

medicineworker

I have fields with named id (int),img (BLOB) in my table called img.It is correct? and I manually insert a picture through the MySQL yog(db administration interface)
Dec 2 '07 #3

codegecko
Expert 100+
P: 533
Hi Alex
I have fields with named id (int),img (BLOB) in my table called img.It is correct?
As mentioned previously, add the square braces and the full-stop, and rename the "img" field to ensure that MySQL is reading the query correctly, otherwise it will be interpreted as "SELECT myTable FROM myTable" - as we all know you can't select a table from a table, so by definition it's not correct.

medicineworker
Dec 2 '07 #4

pbmods
Expert 5K+
P: 5,821
Heya, Alex.

The exciting part of computer programming is getting a machine that does exactly what you tell it to do... to do what you want it to do.

You set up your table correctly, and your query looks right... but the server is misinterpreting it. Try adding the proper delimiters to eliminate the possibility of ambiguity in your query.
Dec 2 '07 #5

P: 6
Hi Alex

As mentioned previously, add the square braces and the full-stop, and rename the "img" field to ensure that MySQL is reading the query correctly, otherwise it will be interpreted as "SELECT myTable FROM myTable" - as we all know you can't select a table from a table, so by definition it's not correct.

medicineworker
Display.asp
Expand|Select|Wrap|Line Numbers
  1.       <HTML>
  2.          <HEAD><TITLE>Display Image</TITLE></HEAD>
  3.          <BODY>
  4.          <IMG SRC="Query.asp">
  5.          </BODY>
  6.          </HTML>
Query.asp
Expand|Select|Wrap|Line Numbers
  1.       <%@ LANGUAGE="VBSCRIPT" %>
  2.       <!-- #include file="../../includes/dbconn.asp"-->
  3.       <%
  4.       dim MyRs, sqlstr, MyConn
  5.  
  6.          Response.Expires = 0
  7. Response.Buffer = TRUE
  8. Response.Clear
  9. Response.ContentType = "image/gif"
  10.  
  11.         Set MyConn = Server.CreateObject("ADODB.Connection")
  12. MyConn.Open dbConn
  13. Set MyRs = Server.CreateObject("ADODB.Recordset")
  14.  
  15. sqlstr="select file from img"
  16. MyRs.Open sqlstr, MyConn, adOpenKeyset, adLockOptimistic
  17.              Response.BinaryWrite MyRs("file")
  18. Response.End
  19.  
  20.       MyRs.Close
  21.       MyConn.Close
  22.  
  23.       set MyRs=nothing
  24. set MyConn= nothing
  25.       %>
My table is called img with fields id(int) and file (blob) . It's correct? why i still can't display.Thanks
Dec 2 '07 #6

P: 37
hi, i was wandering....can you match the picture name with table primary key, so for my project i want to display a picture which also mathces with the primary key with a record, and display it on the screen, automatically.

as when users click the menu from pictures menu, the code automatiicaly does this, and beside the picture i want to display the record details.


thanks....
Dec 29 '07 #7

P: 37
ok i guess nobody knows how to do it
Jan 4 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.