Blob

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    Blob

    Hello Everyone,

    I first want to start off with thanks to anyone that helps me out with this problem. With that said let me ask my question.

    I am developing a .NET webpage using VB.NET. What I am trying to do with in this webpage is to query an Oracle database table that hold PDF documents in a BLOB container/field. After running my query I want to display the PDF from the query on the page. Below is what I have so far from trying to figure it out myself.

    The error that I am currently getting is on line 28: Object reference not set to an instance of an object.

    I have hit my wits end on this one. So, if anyone can help out I would be indebted to them.

    Again, thanks

    CroCrew~

    Code:
    Imports System.IO
    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Sub GetPDF(ByVal IdNumber As Integer)
            Dim con As OracleConnection = New OracleConnection("Data Source=MIB; User ID=web_view; Password=webview;")
            con.Open()
    
            Dim DestinationLoc As String = Server.MapPath("PDF") & "\" & "Data.pdf"
    
            Dim block As String = "SELECT PdfImage FROM PDF WHERE KeyId = " & IdNumber
            Dim cmd As OracleCommand = New OracleCommand()
            cmd.CommandText = block
            cmd.Connection = con
            cmd.CommandType = Data.CommandType.Text
    
            Dim param2 As OracleParameter = cmd.Parameters.Add("blobfromdb", OracleDbType.Blob)
            param2.Direction = Data.ParameterDirection.Output
    
            cmd.ExecuteNonQuery()
    
            Dim byteData As Byte()
            Dim Paramvalue As OracleBlob = cmd.Parameters(0).Value
    
            byteData = CType((Paramvalue.Value), Byte())
    
            Dim ArraySize As Integer = New Integer()
            ArraySize = byteData.GetUpperBound(0)
    
            Dim fs1 As FileStream = New FileStream(DestinationLoc, FileMode.OpenOrCreate, FileAccess.Write)
            fs1.Write(byteData, 0, ArraySize)
            fs1.Close()
    
            Response.Write("Done!")
        End Sub
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            GetPDF(23)
        End Sub
    End Class
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Please check for the value of Paramvalue.Valu e before using Ctype function for converting the value into byte array. The value of Paramvalue.Valu e might be Null. Also you can use try and catch in order to get the exception.

    Comment

    • CroCrew
      Recognized Expert Contributor
      • Jan 2008
      • 564

      #3
      Sorry for not understand but, can you give me an example on what your asking me to do. Thanks~

      Comment

      • CroCrew
        Recognized Expert Contributor
        • Jan 2008
        • 564

        #4
        The Try and Catch returns:

        System.NullRefe renceException: Object reference not set to an instance of an object.

        Comment

        • shweta123
          Recognized Expert Contributor
          • Nov 2006
          • 692

          #5
          Hi,

          Please refer to the following example to solve the error you are getting:




          Originally posted by CroCrew
          The Try and Catch returns:

          System.NullRefe renceException: Object reference not set to an instance of an object.

          Comment

          • CroCrew
            Recognized Expert Contributor
            • Jan 2008
            • 564

            #6
            Thanks, I have everything working now.

            Comment

            Working...