Private Sub InitializeComponent () Me.SqlConn = New System.Data.SqlClient.SqlConnection () Me.SqlComm =
New System.Data.SqlClient.SqlCommand () End Sub Private Sub Page_Init (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init Form Designer InitializeComponent () End Sub # End Region Private Sub Page_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub cmdupload_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdupload.Click Dim image As System.Drawing.Image, newimage As System.Drawing.Image Dim callb As System.Drawing.Image.GetThumbnailImageAbort Dim f As System.IO.File, fs As System.IO.FileStream Dim temppath As String Dim bigdata As Byte (), smalldata As Byte () 'large Image data, small picture data DIM PIC as system.data.sqlclient.sqlparameter, picsmall asseter, picsmall as system.data.sqlclcent.sqlparameter 'Check that the upload file is equipped with standard, the check function is I need to write according to the website, IF Check (file1.postedfile .Filename <> "ok" the response.write (check (file1.postedfile.fi LENAME)) EXIT SUB END IF 'Sets the temporary path, in order to prevent conflicts when multi-user access, set an application object if Application ("Image") = "" "") = 0 end if application.lock () Temppath = Server.mappath ("Image"))) 'Temporary Path Application ("Image") = Application ("Image" 1 Application.unlock ()' Read the data of the image Redim BigData ( (Me.file1.postedFile.InputStream.Length) Me.file1.postedfile.inputStream.read (BigData, 0, Ubound (BigData) 'Read the original image data to BigData' 'Changing the size image =
System.drawing.Image.fromstream (me.file1.postedfile.inputstream) 'NewImage Size can also set up, I only use 80 * 60 and 60 * 80 two kind if image.width> image.Height Ten newimage = Image.getthumbnailimage (80, 60, Callb, New System.intptr (0)) Else newimage = image.getthumbnailimage (60, 80, callb, new system.intptr (0)) end if image.dispose () will And the picture is time to store newimage.save (Temppath, System.drawing.Image.dispose () 'in the temporary path to read the temporary file data into SmallData FS = New System.IO.FileStream (Temppath IO.FileMode.open, IO.FileAccess.read) Redim SmallData (fs.length) fs.read (SmallData, 0, Ubound (SmallData) fs.close () 'The above way to get small pictures, I originally want to use System .io.Memorystream, but not: code as follows: 'Dim M as system.io.MemoryStream'm = new system.io.MemoryStream ()' newimage.save (m, system.drawing.imaging.imageformat.jpeg) 'Redim SmallData (M.LENGTH)' M.Read (SmallData, 0, M.Length) 'But the SmallData read from the above method is empty, do not know why, please advice' delete temporary file IF F.EXISTS (Temppath) ) f.Delete (Temppath) End if 'Adds Data in Database' Due to the image field in the database, I don't insert it with SQL. Use a stored procedure 'to insert the prawn with the SQL statement insertion with an Image field. How to Write 'doesn't work with INSERT INTO TALBE (PIC, PICSMALL) Values ("& BigData &", "& BiGData &" is not available! SqlConn = New System.Data.SqlClient.SqlConnection (connstr) 'may be connected to its own database server provided connstr SqlComm = New System.Data.SqlClient.SqlCommand () SqlComm.CommandType = CommandType.StoredProcedure SqlComm.CommandText = "dbo.image" pic = New system.data.sqlclient.sqlparameter ("