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! ");
}
}
}