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: