上传的:Stream imgDataStream = u_photo.PostedFile.InputStream;
int imgDataLen = u_photo.PostedFile.ContentLength;
byte[] imgDataTemp = new byte[imgDataLen];
imgDataStream.Read( imgDataTemp, 0, imgDataLen );
strSql = "INSERT INTO UserInfo ( u_photo ) VALUES ( ? )";
myConnection.Open();
myCommand = new OleDbCommand( strSql, myConnection );
myCommand.Parameters.Add( ":u_photo", OleDbType.Binary, imgDataLen, "u_photo" ).Value = imgDataTemp;
myCommand.ExecuteNonQuery();显示:string strSql = "SELECT u_photo FROM UserInfo WHERE id = '"+ id +"'";
myConnection.Open();
myCommand = new OleDbCommand( strSql , myConnection );
myReader = myCommand.ExecuteReader();
if ( myReader.Read() )
{
byte[] btImage = ( byte[] )myReader["u_photo"];
Response.BinaryWrite( btImage );
Response.End();
}

解决方案 »

  1.   

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
      

  2.   

    add.aspx.cs创建上传路径字符串
    string filepath=server.mappath("file/"+path.getfilename(file1.postedfile.filename));建立数据库连接
    sqlconnection myconnection=...
    创建sqldataadapter对象,按照指定的sql语句将图片插入到数据库中
    sqlcommand mycommand= new Sqlcommand("insert into aaa(title,img)") values ('"+title.text.tostring()+"','"+path.getfilename(file1.postedfile.filename)+"',myconnection;)
    mycommand.connection.open();
    mycommand.executenonquery();
    mycommand.connection.close();
    response.redirect(bbb.aspx)show.aspx<%if (dr[img].tostring()!=""){%><img src='file/<%=dr["img"] %>'><%}%>
      

  3.   

    http://expert.csdn.net/Expert/topic/2435/2435054.xml?temp=7.767886E-02
      

  4.   

    1、建立一个表:  在SQL SERVER中建立这样结构的一个表:列名  类型 目的  
    ID  Integer  主键ID  
    IMGTITLE  Varchar(50)  图片的标题  
    IMGTYPE  Varchar(50) 图片类型. ASP.NET要以辨认的类型 
    IMGDATA Image 用于存储二进制数据    2、存储图片到SQL SERVER数据库中  为了能存储到表中,你首先要上传它们到你的WEB 服务器上,你可以开发一个web form,它用来将客户端中TextBox web control中的图片入到你的WEB服务器上来。将你的 encType 属性设置为:myltipart/formdata.Stream imgdatastream = File1.PostedFile.InputStream;
    int imgdatalen = File1.PostedFile.ContentLength;
    string imgtype = File1.PostedFile.ContentType;
    string imgtitle = TextBox1.Text;
    byte[] imgdata = new byte[imgdatalen];
    int n = imgdatastream.Read(imgdata,0,imgdatalen);
    string connstr=((NameValueCollection)Context.GetConfig("appSettings"))["connstr"];SqlConnection connection = new SqlConnection(connstr);SqlCommand command = new SqlCommand
             ("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)
             VALUES ( @imgtitle, @imgtype,@imgdata )", connection );SqlParameter paramTitle = new SqlParameter
             ("@imgtitle", SqlDbType.VarChar,50 );paramTitle.Value = imgtitle;
    command.Parameters.Add( paramTitle);SqlParameter paramData = new SqlParameter( "@imgdata", SqlDbType.Image );
    paramData.Value = imgdata;
    command.Parameters.Add( paramData );SqlParameter paramType = new SqlParameter( "@imgtype", SqlDbType.VarChar,50 );
    paramType.Value = imgtype;
    command.Parameters.Add( paramType );connection.Open();
    int numRowsAffected = command.ExecuteNonQuery();
    connection.Close();   3、从数据库中恢复读取  现在让我们来从SQL Server中读取我们放入的数据吧!我们将要输出图片到你的浏览器上,你也可以将它存放到你要的位置。private void Page_Load(object sender, System.EventArgs e)
    {
     string imgid =Request.QueryString["imgid"];
     string connstr=((NameValueCollection)
     Context.GetConfig("appSettings"))["connstr"];
     string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = " + imgid;
     SqlConnection connection = new SqlConnection(connstr);
     SqlCommand command = new SqlCommand(sql, connection);
     connection.Open();
     SqlDataReader dr = command.ExecuteReader();
     if(dr.Read())
     {
      Response.ContentType = dr["imgtype"].ToString();
      Response.BinaryWrite( (byte[]) dr["imgdata"] );
     }
     connection.Close();

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;309158
    http://www.aspx.cn/article/go.asp?id=268&typeid=2
    http://www.aspx.cn/article/go.asp?id=267&typeid=2
    http://www.c-sharpcorner.com/Code/2002/Feb/FlashCardsMG.asp