<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<HTML>
<HEAD>
<script language="vb" runat="server">
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim intImageSize As Int64
Dim strImageType As String
Dim ImageStream As Stream
intImageSize = myFile.PostedFile.ContentLength
strImageType = myFile.PostedFile.ContentType
ImageStream = myFile.PostedFile.InputStream
Dim ImageContent(intImageSize) As Byte
Dim intStatus As Integer
intStatus = ImageStream.Read(ImageContent, 0, intImageSize)
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim myCommand As New SqlCommand("sp_insertimage", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
Dim prmmyFile As New SqlParameter("@myFile", SqlDbType.Image)
prmmyFile.Value = ImageContent
myCommand.Parameters.Add(prmmyFile)
Dim prmmyFileType As New SqlParameter("@myFileType", SqlDbType.VarChar, 255)
prmmyFileType.Value = strImageType
myCommand.Parameters.Add(prmmyFileType)
Try
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()
Response.Write("Salvata!")
Catch SQLexc As SqlException
Response.Write("Errore: " & SQLexc.ToString())
End Try
End Sub
</script>
</HEAD>
<body>
<P><INPUT type="file" id="myFile" name="myFile" runat="server"></P>
<P>
<asp:Button id="Button1" runat="server" Text="Salva" OnClick="Button1_Click"></asp:Button></P>
</body>
</HTML>