1. Write BLOB: String File_name = " D: \ 20080523.jpg " ;
String Conn_str = " Provider = oraoledb. oracle.1; Password = agoodjob; persist Security info = true; user id = AMS; Data Source = IMS; extended properties = " ; // The provider must use oraoledb. oracle.1
Oledbconnection CN = New Oledbconnection (conn_str );
CN. open ();
Oledbcommand cmd = New Oledbcommand ( " Update blob set photo =? " , CN );
Cmd. Parameters. Add ( " Photo " , Oledbtype. Binary );
Filestream FS = New Filestream (file_name, filemode. openorcreate, fileaccess. Read );
Byte [] Mydata = New Byte [Fs. Length];
FS. Read (mydata, 0 , System. Convert. toint32 (FS. Length ));
FS. Close ();
Cmd. Parameters [ " Photo " ]. Value = Mydata;
Try
{
Int Result = Cmd. executenonquery ();
If (Result < 1 )
{
Oledbcommand cmd1 = New Oledbcommand ( " Insert into blob (photo) values (? ) " , CN );
Parameters 1.parameters. Add ( " Photo " , Oledbtype. Binary );
Parameters 1.parameters [ " Photo " ]. Value = Mydata;
Result = Statement 1.executenonquery ();
}
}
Catch (Exception E1)
{
Page. registerstartupscript ( "" , " <Script language = 'javascript '> alert (' " + E1.message + " ') </SCRIPT> " );
}
Finally
{
CN. Close ();
}
2. Read BLOB: String Conn_str = " Provider = oraoledb. oracle.1; Password = agoodjob; persist Security info = true; user id = AMS; Data Source = IMS; extended properties = " ; // The provider must use oraoledb. oracle.1
Oledbdataadapter da = New Oledbdataadapter ();
Dataset DS = New Dataset ();
Oledbconnection Conn = New Oledbconnection (conn_str );
Oledbcommand cmd = New Oledbcommand ( " Select photo from web_db.users where user_id = 1 " , Conn );
Da. selectcommand = CMD;
Cmd. Connection. open ();
Da. Fill (DS );
byte [] IMG = New byte [ 0 ];
datarow Dr;
Dr = DS. tables [ 0 ]. rows [ 0 ];
If ( ! DS. tables [ 0 ]. rows [ 0 ] [ " photo " ]. tostring (). equals ( "" ))
{< br> IMG = ( byte []) dr [ " photo " ];
}
Response. contenttype= "Image /*";
Response. binarywrite (IMG );
Conn. Close ();