下面舉一個從microsoft sql server的pub數(shù)據(jù)庫讀取圖片并顯示它的例子:
| 以下是示例源代碼: <%@ import namespace="system.data.sqlclient" %> <%@ import namespace="system.drawing" %> <%@ import namespace="system.drawing.imaging" %> <%@ import namespace="system.io" %> <script language="c#" runat="server"> void page_load(object sender, eventargs e) { memorystream stream = new memorystream(); sqlconnection connection; connection = new sqlconnection("server=localhost;database=pubs;uid=sa;pwd="); try { connection.open(); sqlcommand command; command = new sqlcommand("select logo from pub_info where pub_id=/’0736/’", connection); byte[] image; image = command.executescalar(); stream.write(image, 0, image.length); bitmap imgbitmap; imgbitmap = new bitmap(stream); response.contenttype = "image/gif"; imgbitmap.save(response.outputstream, imageformat.gif); } finally { connection.close(); stream.clse(); } } </script> |
新聞熱點
疑難解答
圖片精選