Copy codeThe Code is as follows:
// Namespace involved
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Data. SqlClient;
Using System. Drawing;
Using System. Drawing. Drawing2D;
Using System. Drawing. Imaging;
Using System. Web;
Using System. Configuration;
// Method
Public void AddUser (string PersonName, string PersonEmail, string PersonSex, string PersonDOB, string PersonImage, string PersonImageType)
{
String strImageType = userImage. PostedFile. ContentType;
Stream ImageStream = userImage. PostedFile. InputStream;
// Add a watermark --------------->
String wImageFile = Server. MapPath ("/bkwww/image/HomeSign.gif"); // watermark image to be added
Image sImage = Image. FromStream (ImageStream); // create an image from the Http input stream
Image wImage = Image. FromFile (wImageFile );
// Drawing
Graphics g = Graphics. FromImage (sImage );
G. DrawImage (wImage, new Rectangle (0, 0, wImage. Width, wImage. Height), 0, 0, wImage. Width, wImage. Height, GraphicsUnit. Pixel );
// Save and convert the image to byte []
MemoryStream MS = new MemoryStream ();
Byte [] myImage = null;
SImage. Save (MS, ImageFormat. Gif );
MyImage = ms. GetBuffer ();
// ------------------------>
// Write data to the database
String strConn = ConfigurationSettings. etettings ["ConnectionString"];
SqlConnection myConnection = new SqlConnection (strConn );
SqlCommand myCommand = new SqlCommand ("sp_person_isp", myConnection );
MyCommand. CommandType = CommandType. StoredProcedure;
MyCommand. Parameters. Add ("@ PersonEmail", SqlDbType. VarChar, 255). Value = PersonEmail;
MyCommand. Parameters. Add ("@ PersonName", SqlDbType. VarChar, 255). Value = PersonName;
MyCommand. Parameters. Add ("@ PersonSex", SqlDbType. Char, 1 );
If (sexMale. Checked)
MyCommand. Parameters ["@ PersonSex"]. Value = "M ";
Else
MyCommand. Parameters ["@ PersonSex"]. Value = "F ";
MyCommand. Parameters. Add ("@ PersonDOB", SqlDbType. DateTime). Value = PersonDOB;
MyCommand. Parameters. Add ("@ PersonImage", SqlDbType. Image). Value = myImage;
MyCommand. Parameters. Add ("@ PersonImageType", SqlDbType. VarChar, 255). Value = ImageType;
Try
{
MyConnection. Open ();
MyCommand. ExecuteNonQuery ();
MyConnection. Close ();
Response. Write ("added successfully! ");
}
Catch (System. Exception SqlEx)
{
Response. Write ("failed to add! "+ SqlEx. ToString ());
}
}