⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uploadimage.aspx.vb

📁 这是用ASP.NET和SQLserver编写的购物网站的程序
💻 VB
字号:
Imports System.Data.SqlClient
Imports System.Data
Public Class uploadimage
    Inherits System.Web.UI.Page
    Dim Cstring As String = ConfigurationSettings.AppSettings("ConnectionString")
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Dim nwindConn As SqlConnection = New SqlConnection(Cstring)

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents DList1 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents upload As System.Web.UI.HtmlControls.HtmlInputFile
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码

        If Not IsPostBack Then
            Try
                If (Session("userpower") <> 2) Then
                    Response.End()
                End If
            Catch ex As Exception
                Response.Write("您不是管理者,不能打开该页,<a href='webform1.aspx'>返回</a>")
                Response.End()
            End Try
            Session("userpower") = -1
            nwindConn.Open()
            Dim connSQL As String = "select itemname,itemid from item"
            Dim DS As New DataSet
            Dim adapter As New SqlDataAdapter(connSQL, nwindConn)
            adapter.Fill(DS)
            DList1.DataSource = DS.Tables(0)
            DList1.DataTextField() = DS.Tables(0).Columns("itemname").ToString
            DList1.DataValueField() = DS.Tables(0).Columns("itemid").ToString
            DList1.DataBind()
            DS.Dispose()
            adapter.Dispose()
            nwindConn.Close()
        End If

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim filename As String = Request.Files("upload").FileName.Substring(Request.Files("upload").FileName.LastIndexOf("\") + 1)
        nwindConn.Open()
        Dim cmd As New SqlCommand
        cmd.CommandText = "update item set image='" & filename & "' where itemid ='" & DList1.SelectedValue & "'"
        cmd.Connection = nwindConn
        cmd.ExecuteNonQuery()
        nwindConn.Close()
        Request.Files("upload").SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") & filename)
        Dim strscript As String = "<script language=javascript>alert('提交成功')</script>"
        RegisterClientScriptBlock("系统消息", strscript)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Session("userpower") = 2
        Response.Redirect("manager.aspx")
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -