Store pictures (c#+winform+sql Server) (columns from Xlkun hacken)

Source: Internet
Author: User
Server

Read the picture to PictureBox, then write to the database

SqlConnection conn=new SqlConnection (@ "Data source=chenyuming2004\vsdotnet;uid=sa;pwd=cym;database=lhf");
Conn. Open ();
SqlCommand cmd=new SqlCommand ("INSERT into fuser values (' 1a ', ' 1b ', @i)", conn);
Byte[] Ib=new byte[60000];
FileStream fs=new FileStream (@ "D:\windows temp\temp\1.jpg", FileMode.Open, FileAccess.Read);
Fs. Read (ib,0,60000);
Cmd. Parameters.Add ("@i", Sqldbtype.image, (int) fs. Length);
Cmd. parameters["@i"]. Value=ib;
Cmd. ExecuteNonQuery ();
Conn. Close ();

-------------------------------------------------------
Read pictures from database to PictureBox

SqlConnection conn=new SqlConnection (@ "Data source=chenyuming2004\vsdotnet;uid=sa;pwd=cym;database=lhf");
Conn. Open ();
SqlCommand cmd=new SqlCommand ("Select photos from fuser where password= ' 1b '", conn);
SqlDataReader Reader=cmd. ExecuteReader ();
Reader. Read ();
MemoryStream buf=new MemoryStream ((byte[)) reader[0]);
Image Image=image.fromstream (buf,true);
Picturebox1.image=image;




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.