在你的<form></form>里加上 enctype="multipart/form-data"
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
解决方案 »
- 菜牛,新手给解决一下
- 如何实现:点击button控件,在新窗口打开网址
- 请问设计时能动态变更web.config中的handlers么
- 急!CalenderExtender超出网页下边界的问题
- 版主和高手近,十万火急!页面编码问题!
- 如何在DataGrid中加新数据
- 部署使用 Crystal Reports for Visual Studio .NET 2003 的程序 问题
- 求从数据库读取的动态三级树型菜单的asp代码
- 如何同时获得datagrid中每行记录的id号和行中的内容呀?
- Asp.net 图片上传到服务器,并立即显示出来(2)
- 面对这样的汉奸!除了气愤已无话可说!!!(转贴)
- 如何使用findcontrol?急救!
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