Polje treba biti tipa Image. Kod ide otprilike ovako:
Code:
string FileName;
string ConnectionString;
System.Data.SqlClient.SqlConnection Connection;
System.Data.SqlClient.SqlCommand Command;
System.IO.Stream FileStream;
// Set the file name and connection string
FileName = "C:\\Temp\\Test.doc";
ConnectionString = "data source=.;initial catalog=Test;persist security info=False;user id=sa;password=;packet size=4096;Connect Timeout=240";
// Open file stream
FileStream = System.IO.File.OpenRead(FileName);
byte[] FileContents=new byte[FileStream.Length - 1];
// Read contents of file into Byte array
FileStream.Read(FileContents, 0, (int)FileStream.Length);
// Close file stream
FileStream.Close();
// Create connection to database
Connection = new System.Data.SqlClient.SqlConnection (ConnectionString);
// Create insert command
Command = new System.Data.SqlClient.SqlCommand("INSERT INTO Test(FileContents) VALUES (@FILECONTENTS)", Connection);
Command.Parameters.Add (new System.Data.SqlClient.SqlParameter("@FILECONTENTS", FileContents));
// Open connection
Connection.Open();
// Perform update
Command.ExecuteNonQuery();
// Close connection
Connection.Close()