private void btnupload_Click(object sender, EventArgs e)
{
try
{
openFileDialog1.ShowDialog(this);
openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
byte[] image;
string fileName =openFileDialog1.FileName;
FileStream fs = new FileStream(fileName, FileMode.Open);
BinaryReader reader = new BinaryReader(fs);
image = reader.ReadBytes((int)fs.Length);
fs.Close();
SqlConnection conn = new SqlConnection("connectionString");
conn.Open();
string query = "Insert into pictures (name,images) values(@name,@images)";
SqlCommand comm = new SqlCommand(query, conn);
comm.Parameters.AddWithValue("name", Path.GetFileName(strFn).ToString());
comm.Parameters.AddWithValue("images", image);
comm.ExecuteNonQuery();
MessageBox.Show("Record Added");
conn.Close();
bind();
pictureBox1.Image = new Bitmap(strFn);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}