Public Static Void Main ()
{
// Write large objects Sqlserver
Filestream FS = New Filestream ( " C: \ test.bmp " , Filemode. Open, fileaccess. Read );
Binaryreader br = New Binaryreader (FS );
Sqlconnection Conn = New Sqlconnection ( " Server = localhost; uid = sa; Pwd = sa; database = northwind " );
String Plain text = " Update employees " +
" Set photo = @ image where employeeid = 1 " ;
Sqlcommand cmd = New Sqlcommand (plain text, Conn );
Cmd. Parameters. Add ( " @ Image " , Sqldbtype. Image );
Cmd. Parameters [ " @ Image " ]. Value = BR. readbytes (( Int ) Br. basestream. Length );
Conn. open ();
Int I = Cmd. executenoquery ();
// Read large objects from SQL Server
String Plain text = " Select employeeid, photo " +
" From employees where employeeid = 1 " ;
Sqlcommand cmd2 = New Sqlcommand (plain text, Conn );
Filestream RFS;
Binarywriter rbw;
Long Numread;
Long Startindex;
Int Buffsize = 4096 ;
Byte [] Buff = New Byte [Buffsize];
Conn. open ();
Sqldatareader RDR = Cmd. executereader (commandbehavior. sequentialaccess );
If (RDR. Read ())
{
Int Empid = RDR. getint32 ( 0 );
FS = New Filestream ( " C: \ mypic.bmp " , Filemode. openorcreate, fileaccess. Write );
BW = New Binarywrite (FS );
Startindex = 0 ;
Numread = RDR. getbytes ( 1 , Startindex, buff, 0 , Buffsize );
While (Numread = Buffsize)
{
Bw. Write (buff );
Bw. Flush ();
Startindex+ =Buffsize;
Numread=RDR. getbytes (1, Startindex, buff, buffsize );
}
Bw. Write (buff );
Bw. Flush ();
Bw. Close ();
FS. Close ();
}
RDR. Close ();
conn. Close ();
}