Save Read BLOB Oracle

Source: Internet
Author: User
Tags oracleconnection lenovo

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Using System.Data.OracleClient;
Using System.IO;

Namespace Testoraclblob
{
public partial class Form1:form
{
OracleConnection Conn;
Public Form1 ()
{
InitializeComponent ();
String Strcon = "Data source=orcl; Persist Security info=true; User Id=wcq; password=wcq123; Unicode=true; ";
conn = new OracleConnection (Strcon);
}
Write to Database
private void Button1_Click (object sender, EventArgs e)
{
OracleCommand cmd = new OracleCommand ("", conn);

string path = @ "C:\Users\lenovo\Desktop\01.pdf";
FileStream fs = new FileStream (path, FileMode.Open, FileAccess.Read);
byte[] Fsbyte = new Byte[fs. Length]; Turn a picture into a byte-type binary stream
Fs.   Read (fsbyte, 0, fsbyte.length); Read the binary stream into the buffer
Fs. Close ();

Cmd.commandtext = "INSERT into Student (ID,NAME,STOREBLOB) VALUES (1, ' AA ',: ZP)";
Cmd. Parameters.Add (": ZP", Oracletype.bfile, Fsbyte.length);
Cmd. Parameters[0]. Value = Fsbyte;

Conn. Open ();
Cmd. ExecuteNonQuery ();

MessageBox.Show ("Insert succeeded! ");
Conn. Close ();
}

private void Button2_Click (object sender, EventArgs e)
{
string path = @ "C:\Users\lenovo\Desktop\2.pdf";

DataTable dt = new DataTable ();
OracleDataAdapter adapter = new OracleDataAdapter ("Select Storeblob from Student", Conn);

Adapter. Fill (DT);
Byte[] Filebyte = (byte[]) (dt. Rows[1][0]);

FileStream fs = new FileStream (path, filemode.create);


Fs. Write (filebyte, 0, Filebyte. GetLength (0));

Fs. Close ();

MessageBox.Show ("Read success! ");
}
}

}

Related Article

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.