How to: C # in WinForm How to save image in SQL2000 and remove display

Source: Internet
Author: User

Save
Sql= "INSERT into P_ry_photo (Id,photo) VALUES ('" +id+ "', @i)";
SqlCommand cmd=new SqlCommand (sql,commonvar.sqlcondatabase);
MemoryStream s = new MemoryStream ();
PicPhoto.Image.Save (S,system.drawing.imaging.imageformat.jpeg);
Byte[] B = S.toarray ();
S.close ();
Cmd. Parameters.Add ("@i", Sqldbtype.image, (int) b.length);
Cmd. parameters["@i"]. Value=b;
Cmd. ExecuteNonQuery ();

Reading images

private void Readphoto (string id)
{
Try
{
String ls_sql= "Select photo from P_ry_photo where id= '" +id+ "'";
This.picphoto.image=null;
This.picPhoto.Refresh ();
SqlCommand cmd=new SqlCommand (ls_sql,commonvar.sqlcondatabase);
SqlDataReader Reader=cmd. ExecuteReader ();
while (reader. Read ())
{
Byte[] B = (byte[]) reader[0];
MemoryStream s = new MemoryStream (b);
Bitmap bmp = new Bitmap (s);
System.Drawing.Image Image = BMP;
Picphoto.image = Image;
S.close ();
}
Reader. Close ();
}
catch (Exception ex)
{
MessageBox.Show (ex. Message);
}
}

It is recommended to save the uploaded image as a file and then store the path in the database. Database read and write pictures take too long, it is not cost-effective.

How to: C # in WinForm How to save image in SQL2000 and remove display

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.