Regular, direct analysisCode
First, create a table. The field type is image.
Normally, you will find that there is no way to store the image, because the length is 50 and cannot be changed. A single image is usually more than 1000
The length of the image data type is 16. When I save a graph, the maximum size of the graph can be about 30 kb. A large graph cannot be saved at all. I want to change its length, but it cannot.
Run the following statement:
Sp_tableoption n 'mytable', 'text in row', and '123456' are effective only when this image type data is executed.
Second, convert the file to a byte array of binary data.
Convert files into binary data
Public static byte [] picturefiletobyte (string picfilepath)
{
Filestream FS = new filestream (picfilepath, filemode. Open, fileaccess. Read );
Byte [] bytephoto = new byte [fs. Length];
FS. Read (bytephoto, 0, (INT) fs. Length );
FS. Close ();
Return bytephoto;
}
The image is saved to the database.
Read
Create an image control, image. imageurl = image. aspx? Id = 2002
2002 is the row ID of the table storing images in the database,
Image. aspx
Protected void page_load (Object sender, eventargs E)
{
String guid = request. querystring ["ID"];
If (guid! = NULL)
{
Response. clearcontent ();
Response. contenttype = "image/JPEG ";
Byte [] DATA = utility. Picture (guid); read binary data bytes
Response. binarywrite (byte []) data );
}
}
In this way, you can.
If you have any questions, please leave a message.