| private void Button2_Click(object sender, System.EventArgs e)
{
Stream inputStream = File1.PostedFile.InputStream;
int imageLength = File1.PostedFile.ContentLength;
byte[] imageBinary = new byte[imageLength];
int inputRead = inputStream.Read(imageBinary,0,imageLength);
byte[] imageData = imageBinary;
string connectionString = (string) ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(connectionString);
string insertQuery = @"INSERT INTO Person(Name,Email,Picture)
VALUES(@Name,@Email,@Picture)";
SqlCommand myCommand = new SqlCommand(insertQuery,myConnection);
myCommand.CommandType = CommandType.Text;
myCommand.Parameters.Add("@Name",SqlDbType.NVarChar,50);
myCommand.Parameters["@Name"].Value = "New User";
myCommand.Parameters.Add("@Email",SqlDbType.NVarChar,50);
myCommand.Parameters["@Email"].Value = "someone@somewhere.com";
myCommand.Parameters.Add("@Picture",SqlDbType.Image,16);
myCommand.Parameters["@Picture"].Value = imageData;
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
} |