Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > [VB.NET] สอบถามการ Select ข้อมูล Blob จาก Oracle โดยมีปัญหาไม่สามารถ query ได้เหมือนข้อมูลปกติ



 

[VB.NET] สอบถามการ Select ข้อมูล Blob จาก Oracle โดยมีปัญหาไม่สามารถ query ได้เหมือนข้อมูลปกติ

 



Topic : 058052

Guest




[VB.NET]

สอบถามการ Select ข้อมูล Blob จาก Oracle โดยมีปัญหาไม่สามารถ query ได้เหมือนข้อมูลปกติ

และมี Error แจ้งมา ในส่วนโค้ด ds.Fill(dt)

รายละเอียดดังนี้

Unspecified error Oracle error occurred, but error message could not be retrieved from Oracle. Data type is not supported.

ผมจะจัดการยังไงครับ





Tag : .NET, VB.NET







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-03-30 13:43:00 By : l0gin View : 2509 Reply : 3
 

 

No. 1

Guest


Code
CREATE TABLE TestBlob (id number, photo BLOB);


Code (VB.NET)
Imports System
Imports System.Data
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.IO
Imports System.Text

'Step 1
' Connect to database
' Note: Modify User Id, Password, Data Source as per your database setup
Dim constr As String = "User Id=Scott;Password=tiger;Data Source=orcl9i"
Dim con As OracleConnection = New OracleConnection(constr)
con.Open()
Console.WriteLine("Connected to database!")

' Step 2

' Note: Modify the Source and Destination location
' of the image as per your machine settings
Dim SourceLoc As String = "D:/Images/photo.jpg"
Dim DestinationLoc As String = "D:/Images/TestImage.jpg"

' provide read access to the file
Dim Fs As FileStream = New FileStream(SourceLoc,
                       FileMode.Open, FileAccess.Read)

' Create a byte array of file stream length
Dim ImageData As Byte()
ReDim imagedata(fs.Length)

'Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))

'Close the File Stream
fs.Close()

' Step 3
' Create Anonymous PL/SQL block string
Dim block As String =
   " BEGIN " & _
   " INSERT INTO testblob (id, photo) VALUES (100, :1) ;" & _
   " SELECT photo into :2 from testblob WHERE id = 100 ;" & _
   " end ;"

' Set command to create Anonymous PL/SQL Block
Dim cmd As OracleCommand = New OracleCommand()
cmd.CommandText = block
cmd.Connection = con


' Since executing an anonymous PL/SQL block, setting the command type
' as Text instead of StoredProcedure
cmd.CommandType = CommandType.Text

' Step 4
' Setting Oracle parameters

' Bind the parameter as OracleDbType.Blob
' to command for inserting image
Dim param As OracleParameter = cmd.Parameters.Add("blobtodb", OracleDbType.Blob)
param.Direction = ParameterDirection.Input

' Assign Byte Array to Oracle Parameter
param.Value = ImageData


' Bind the parameter as OracleDbType.Blob
' to command for retrieving the image
Dim param2 As OracleParameter = cmd.Parameters.Add("blobfromdb", OracleDbType.Blob)
param2.Direction = ParameterDirection.Output


' Step 5
' Execute the Anonymous PL/SQL Block
' The anonymous PL/SQL block inserts the image to the database and then retrieves
' the images as an output parameter
cmd.ExecuteNonQuery()
Console.WriteLine("Image file inserted to database from "+ SourceLoc)


' Step 6
' Save the retrieved image to the DestinationLoc in the file system
' Create a byte array
Dim byteData As Byte()
Dim Paramvalue As OracleBlob
Paramvalue = cmd.Parameters(1).Value

' fetch the value of Oracle parameter into the byte array
byteData = CType((Paramvalue.Value), Byte())

' get the length of the byte array
Dim ArraySize As Integer = New Integer()
ArraySize = byteData.GetUpperBound(0)

' Write the Blob data fetched from database to the filesystem at
' the destination location
Dim fs1 As FileStream = New FileStream(DestinationLoc, 
                                       FileMode.OpenOrCreate, FileAccess.Write)
fs1.Write(byteData, 0, ArraySize)
fs1.Close()

Console.WriteLine("Image saved to " + DestinationLoc + " successfully !")
Console.WriteLine("")
Console.WriteLine("***********************************************************")

Console.WriteLine("Before running this application again, execute 'Listing 1' "
Console.WriteLine("given in 'Create Database Objects' section in the How-to.")
Console.WriteLine("***********************************************************")







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-30 15:08:48 By : test
 


 

No. 2

Guest


ขอบคุณมากครับ

รัก thaicreate ที่สุด


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-03-30 15:52:07 By : l0gin
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code (VB.NET)
Imports System.Data
Imports System.Data.OracleClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New OracleConnection
            Dim strConnString, strSQL As String

			strConnString = "Data Source=TCDB;User Id=myuser;Password=mypassword;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (:sName,:sFilesName,:sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New OracleCommand(strSQL, objConn)
            objCmd.Parameters.Add(":sName", OracleType.VarChar).Value = Me.txtName.Text
            objCmd.Parameters.Add(":sFilesName", OracleType.Blob).Value = imbByte
            objCmd.Parameters.Add(":sFilesType", OracleType.VarChar).Value = strMIME
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class


Go to : ASP.NET Oracle BLOB Binary Data and Parameterized Query
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-06-02 18:09:59 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : [VB.NET] สอบถามการ Select ข้อมูล Blob จาก Oracle โดยมีปัญหาไม่สามารถ query ได้เหมือนข้อมูลปกติ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่