Store BLOB data in C,

Source: Internet
Author: User

I now write a stored procedure in Oracle as follows:
Create or replace procedure update_student_clob (
V_cmid in number, -- table's primary key ID
V_geometry in blob -- New graphic object
)
Is
Lobloc blob;
Query_str varchar2 (1000 );
Begin
-- Retrieve BLOB Object
Query_str: = 'selectSphoto From student where Studentid =: ID for Update ';
Execute immediate query_str into lobloc using v_cmid;
-- Update
Dbms_lob.write (lobloc, utl_raw.length (v_geometry), 1, v_geometry );

Commit;
End;

In C #,CodeParts are as follows:
1. Data Layer
Public override void runprocedure (string storedprocname, oracleparameter [] parameters)

{
Cmd. commandtext = storedprocname; // declare the name of the stored procedure

Cmd. commandtype = commandtype. storedprocedure;

Foreach (oracleparameter parameter in parameters)

{
Cmd. Parameters. Add (parameter );
}

Cmd. executenonquery (); // execute the Stored Procedure

}

2. Business Layer
// Used to store photos. stuentity is an entity class.
Public void addstudent (stuentity p_entity)
{
Dataaccess. dboperator m_ora = dboperator. createkginstance ();
Try
{
// FS creates a file stream
Filestream FS = new filestream (p_entity.photo, filemode. openorcreate );
// Creates a binary array.
Byte [] blob = new byte [fs. Length];
FS. Read (blob, 0, blob. Length );
FS. Close ();
// Studid is the primary key
String m_ SQL = "Update student set sphoto = empty_blob () WhereStudentid = 1 ";
M_ora.execute (m_ SQL );
Spexefor (1, blob );
}
Catch (exception ex)
{
Throw ex;
}
Finally
{
M_ora.close ();
}
}

Public void spexefor (INT p_studid, byte [] p_blob)

{
Dataaccess. dboperator m_ora = dboperator. createkginstance ();
Try
{
// Parameter declaration of Stored Procedure
Oracleparameter [] parameters = {
New oracleparameter ("v_cmid", oracletype. int32 ),
New oracleparameter ("v_geometry", oracletype. Blob, p_blob.length ),
};
Parameters [0]. value = p_studid;
Parameters [1]. value = p_blob;
M_ora.runprocedure ("update_student_clob", parameters );
}
Catch (exception E)
{
Throw E;
}
Finally
{
M_ora.close ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.