Write the image c: \ 1.jpg to the Cinfo table.
CopyCode The Code is 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 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 );
}
Test. aspxCopy codeThe Code is 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 );
}
}
Page test2.aspx used to display imagesCopy codeThe Code is as follows: