View Single Post
  #4 (permalink)  
Old November 22nd, 2005, 03:57 PM
SQLScott's Avatar
SQLScott SQLScott is offline
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Use a byte array. The following example illustrates:

int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read (pic, 0, len);
// Insert the image and comment into the database
SqlConnection connection = new SqlConnection _ (@"server=Servername;database=databasename;uid=sa;pwd=password");
try
{
connection.Open ();

SqlCommand cmd = new SqlCommand ("insert into Image " + "(Picture, Comment) values (@pic, @text)", connection);

cmd.Parameters.Add ("@pic", pic);
cmd.Parameters.Add ("@text", Comment.Text);
cmd.ExecuteNonQuery ();


Reply With Quote