what data provider are you using?if you are using ODP.NET, seeHow to: Read and Write BLOB Data to a Database Table Through an Anonymous PL/SQL Block 
http://www.oracle.com/technology/sample_code/tech/windows/odpnet/howto/anonyblock/index.html

解决方案 »

  1.   

    您好!!!感谢回复!!我已经把图片存进oracle中,但是,取不出来.总报错!!
    下面是我的原代码和报错信息:希望能在百忙之中帮帮忙!!!谢谢!!!OleDbConnection mycon=new OleDbConnection(Base.Base.getConnectionString());
    mycon.Open();
    da.SelectCommand= new System.Data.OleDb.OleDbCommand("select ZDH,TH from lstowngkcx.T1 where ZDH='"+txt1.Text.Trim()+"'",mycon);
    da.Fill(ds,"lstowngkcx.T1");
    dv1=new System.Data.DataView(ds.Tables["lstowngkcx.T1"]);
    if (dv1.Count > 0) 
    {
    this.DR1 =this.dv1[0].Row;
    if(!Information.IsDBNull(RuntimeHelpers.GetObjectValue(this.DR1["TH"]))) { this.Response.BinaryWrite(((byte[]) this.DR1["TH"]));
    }
    else
    {
    Response.Write("暂无图片");
    }
    }
    else
    {
    Response.Write("暂无图片");
    } mycon.Close();
    未指定的错误发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: 未指定的错误发生了一个 Oracle 错误,但无法从 Oracle 中检索错误信息。数据类型不被支持。源错误: 
    行 42: da.Fill(ds,"lstowngkcx.T1");
      

  2.   

    what is the data type for ZDH? what about TH?
      

  3.   

    那是数据库中的两个字段(属性).zdh代表宗地号(char)th代表图片的内容(blob)
      

  4.   

    I don't have oracle, so I cannot test it for you, but I would suggest you use System.Data.OracleClient or ODP.NET from Oracle
      

  5.   

    how to use System.Data.OracleClient or ODP.NET ?
      

  6.   

    嘿,兄弟能把你将图片存到oracle中的代码贴出来吗?我就是存不进去,但能取出来!
    从oracle中取图片,并显示
    Dim conn As New OracleClient.OracleConnection()
            Dim cmd As New OracleClient.OracleCommand()
            Dim myReader As OracleClient.OracleDataReader
            Dim sql As String
            Dim fl As File        sql = "select jt from sd_gtzp"  '从数据库中取出图片数据 blob
            conn.ConnectionString = "Password=jlsbgis;User ID=jlsbgis;Data Source=sj"
            cmd.CommandText = sql
            cmd.Connection = conn        conn.Open()
            myReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)
            myReader.Read()        Dim fs As FileStream                 ' Writes the BLOB to a file (*.bmp).
            Dim bw As BinaryWriter               ' Streams the binary data to the FileStream object.
            Dim bufferSize As Integer = 1000      ' The size of the BLOB buffer.
            Dim outbyte(bufferSize - 1) As Byte  ' The BLOB byte() buffer to be filled by GetBytes.
            Dim retval As Long                   ' The bytes returned from GetBytes.
            Dim startIndex As Long = 0           ' The starting position in the BLOB output.       
            Dim fpath As String        fpath = Server.MapPath(Request.ApplicationPath) & "\Image\photo.bmp" '将图片数据存成本地文件
            fs = New FileStream(fpath, FileMode.OpenOrCreate, FileAccess.Write)
            bw = New BinaryWriter(fs)        ' Reset the starting byte for a new BLOB.
            startIndex = 0        ' Read bytes into outbyte() and retain the number of bytes returned.
            retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize)        ' Continue reading and writing while there are bytes beyond the size of the buffer.
            Do While retval = bufferSize
                bw.Write(outbyte)
                bw.Flush()
                
                ' Reposition the start index to the end of the last buffer and fill the buffer.
                startIndex = startIndex + bufferSize
                retval = myReader.GetBytes(0, startIndex, outbyte, 0, bufferSize)
            Loop        ' Write the remaining buffer.
            bw.Write(outbyte)
            bw.Flush()
            
            ' Close the output file.
            bw.Close()
            fs.Close()        ' Close the reader and the connection.
            myReader.Close()
            conn.Close()               Dim logo As Image               '文件格式转换
            logo = Image.FromFile(fpath)
            fpath = Server.MapPath(Request.ApplicationPath) & "\Image\zkjhy.jpeg"
            logo.Save(fpath, System.Drawing.Imaging.ImageFormat.Jpeg)
            
            Me.Image1.Width = New Unit(300) '调整显示大小
            Me.Image1.Height = New Unit(350)
            Me.Image1.ImageUrl = "image/zkjhy.jpeg"
      

  7.   

    System.Web.HttpPostedFile UpFile = UploadFile.PostedFile;
    System.Byte[] FileByteArray = new System.Byte[UploadFile.PostedFile.ContentLength];
    System.IO.Stream StreamObject = UpFile.InputStream;
    StreamObject.Read(FileByteArray,0,UploadFile.PostedFile.ContentLength);
    OleDbConnection mycon=new OleDbConnection(Base.Base.getConnectionString());//路径
    System.String SqlCmd = "INSERT INTO T1 (ZDH,TH) VALUES (?,?)";
    System.Data.OleDb.OleDbCommand OleDbCmdObj = new System.Data.OleDb.OleDbCommand(SqlCmd, mycon);
    OleDbCmdObj.Parameters.Add("@ZDH", System.Data.OleDb.OleDbType.VarChar,50).Value = txt1.Text;
    OleDbCmdObj.Parameters.Add("@TH", System.Data.OleDb.OleDbType.LongVarBinary,UploadFile.PostedFile.ContentLength).Value =FileByteArray;
    mycon.Open();
    OleDbCmdObj.ExecuteNonQuery();
    mycon.Close();