asp.net picture of Read and write warehousing implementation Code _ Practical skills

Source: Internet
Author: User
Write the picture c:\1.jpg to the table Cinfo
Copy Code code as follows:

private static void Addcinfo ()
{
String strSQL = "INSERT into Cinfo (Srvtitle,csttitle,introduction,logo) values

(@srvtitle, @csttitle, @introduction, @logo) ";
sqlparameter[] Parms =
{
New SqlParameter ("@srvtitle", sqldbtype.varchar,30),
New SqlParameter ("@csttitle", sqldbtype.varchar,30),
New SqlParameter ("@introduction", sqldbtype.nvarchar,500),
New SqlParameter ("@logo", Sqldbtype.image)
};
Parms[0]. Value = "Travel industry interaction";
PARMS[1]. Value = "LYHD";
PARMS[2]. Value = "Introduction";

String filePath = @ "C:\1.jpg";
FileStream fs = File.openread (FilePath);

byte[] content = new Byte[fs. Length];

Fs. Read (content, 0, content. Length);

Fs. Close ();

PARMS[3]. Value = content;

Dbhelper.executenonquery (CommandType.Text, strSQL, parms);
}

Read a picture page test.aspx
Copy Code code as follows:

protected void Page_Load (object sender, EventArgs e)
{
String strSQL = "SELECT * from Cinfo where id=1";
SqlDataReader Reader=dbhelper.executereader (CommandType.Text, strSQL, NULL);
if (reader. Read ())
{
Byte[] c= (byte[]) reader["logo"];
Response.BinaryWrite (c);
}
}

The page used to display the picture test2.aspx
Copy Code code as follows:


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.