下面举一个从microsoft sql server的pub数据库读取图片并显示它的例子:
以下是示例源代码: <%@ 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> |
新闻热点
疑难解答
图片精选