在你的<form></form>里加上 enctype="multipart/form-data"
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">

解决方案 »

  1.   

    Imports System.Data
    Imports System.Data.SqlClient
    Public Class sell_zp
        Inherits System.Web.UI.Page
        Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile
        Protected WithEvents theValue As System.Web.UI.HtmlControls.HtmlInputHidden
        Protected WithEvents Label1 As System.Web.UI.WebControls.Label
        Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton#Region " Web 窗体设计器生成的代码 "    '该调用是 Web 窗体设计器所必需的。
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()    End Sub    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
            'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
            '不要使用代码编辑器修改它。
            InitializeComponent()
        End Sub#End Region
        Dim cn As New GwConnection()
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '在此处放置初始化页的用户代码
        End Sub
        Function SaveToDB(ByVal imgbin As Byte(), ByVal type As String) As Integer
            Dim connection As SqlConnection = cn.GetCN
            Dim command = New SqlCommand("INSERT INTO tmpImg(imgId,imgData,modDate) VALUES ( @img_name, @img_data,@type)", connection)
            Dim param0 = New SqlParameter("@img_name", SqlDbType.VarChar, 50)
            param0.Value = Trim(theValue.Value)
            command.Parameters.Add(param0)        Dim param1 = New SqlParameter("@img_data", SqlDbType.Image)
            param1.Value = imgbin
            command.Parameters.Add(param1)        Dim param2 = New SqlParameter("@type", SqlDbType.VarChar)
            param2.Value = type
            command.Parameters.Add(param2)
            connection.Open()
            Dim numRowsAffected As Integer = command.ExecuteNonQuery()
            connection.Close()
            SaveToDB = numRowsAffected
        End Function    Private Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
            Dim imgLen As Integer
            Label1.Text = "正在上传图片,请稍等..."
            imgLen = File1.PostedFile.ContentLength
            Dim imgContentType As String = File1.PostedFile.FileName
            Dim imgName As String = imgContentType
            Dim imgBinaryData As Byte()
            ReDim imgBinaryData(imgLen)
            Dim n As Integer = File1.PostedFile.InputStream.Read(imgBinaryData, 0, imgLen)
            Dim RowsAffected As Integer = SaveToDB(imgBinaryData, DateTime.Now)
            If (RowsAffected > 0) Then
                Label1.Text = ""
                Response.Write("<script FOR=window EVENT=onload>window.alert(""保存成功"");</script>")
            End If
            imgBinaryData = Nothing
        End Sub
    End Class
      

  2.   

    多谢,已经解决,但请问为什么要在<form>里加上那位参数?