Thursday, September 1, 2011

// Source Code for saving the image file into the database//


public void OnUpload(Object sender, EventArgs e)
{
  // Create a byte[] from the input file

  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=INDIA\INDIA;database=iSense;uid=sa;pwd=i ndia");
  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 ();
  }
  finally
  {
  connection.Close ();
  }
}

No comments:

Post a Comment