当前位置:编程学习 > C#/ASP.NET >>

asp.net 中怎么存储和读取 oracle BLOB 类型的图片

小弟 实在写不出来 求那位高手 指点下 最好 写个事例 源码 给小弟
答案:首先在sql server中建立一个图片存储的数库表,sqlscript如下: 



if exists (select * from dbo.sysobjects where id = object_id(n"[dbo].[image]") and objectproperty(id, n"isusertable") = 1)
drop table [dbo].[image]
go



create table [dbo].[image] (
 [img_pk] [int] identity (1, 1) not null ,
 [img_name] [varchar] (50) null ,
 [img_data] [image] null ,
 [img_contenttype] [varchar] (50) null 
) on [primary] textimage_on [primary]
go



alter table [dbo].[image] with nocheck add 
 constraint [pk_image] primary key  nonclustered 
 (
  [img_pk]
 )  on [primary] 
go
一、上传图片:
imgupload.aspx文件:
<%@ page language="c#" codebehind="imgupload.aspx.cs" autoeventwireup="false" inherits="study.uploadimage.imgupload" %>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
 <head>
  <title>imgupload</title>
  <meta name="generator" content="microsoft visual studio 7.0">
  <meta name="code_language" content="c#">
  <meta name="vs_defaultclientscript" content="javascript">
<meta name="vs_targetschema" content=" http://schemas.microsoft.com/intellisense/ie5">
 </head>
 <body>
  <form enctype="multipart/form-data" runat="server" id="form1" name="form1">
   文件名 <input type="text" id="imgname" runat="server" name="imgname">
   <br>
   选择文件 <input id="uploadfile" type="file" runat="server" name="uploadfile">
   <br>
   <asp:button text="上传" runat="server" id="button1" />
  </form>
  <a href=> </body>
</html>



codebehind文件:
using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.io;
using system.data.sqlclient;



namespace study.uploadimage
{
 /// <summary>
 /// imgupload 的摘要说明。
 /// </summary>
 public class imgupload : system.web.ui.page
 {
  protected system.web.ui.webcontrols.button button1;
  protected system.web.ui.htmlcontrols.htmlinputtext imgname;
  protected system.web.ui.htmlcontrols.htmlinputfile uploadfile;
 
  private void page_load(object sender, system.eventargs e)
  {
   // 在此处放置用户代码以初始化页面
  }
private void button1_click(object sender, system.eventargs e)
  {
   stream imgstream;
   int imglen;
   string imgname_value;
   string imgcontenttype;
   string imguploadedname;
   
   imgstream  = uploadfile.postedfile.inputstream;
   imglen =  uploadfile.postedfile.contentlength;
   imguploadedname = uploadfile.postedfile.filename;

上一个:asp.net 后台生成16个不同的字符的随机数
下一个:求3到5篇关于ASP.NET或C#的英文文献

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,