文件上传路径输入数据库 [英] File upload path entered into database

查看:72
本文介绍了文件上传路径输入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试将文件的上传路径写入sql服务器数据库.文件上传正常,但是没有任何内容输入数据库吗?

任何帮助将是最欢迎的.

谢谢

Hi
I am trying write the upload path of a file to sql server database. The file uploads fine, but nothing is being entered into the database?

Any help would be most welcome.

Thanks

 Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnConfirm.Click

        If IsPostBack Then
            Dim path As String = Server.MapPath("~/UploadedVideos/")
            If FileUploadVideo.HasFile Then
                If isValidExtension(System.IO.Path.GetExtension(FileUploadVideo.FileName).ToLower()) Then
                    Using Conn As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
                        Try
                            Dim FilePath = path & FileUploadVideo.FileName + fileExtension
                            Dim SQL As String = "INSERT INTO [Video] ([VideoName], [CourseNo], [ModuleNo], [VideoUrl]) VALUES (@VideoName, @CourseNo, @ModuleNo, @VideoUrl)"
                            Dim cmd As New SqlCommand(SQL, Conn)
                            cmd.Parameters.AddWithValue("@VideoName", txtVideoName.Text.Trim())
                            cmd.Parameters.AddWithValue("@CourseNo", cboCourse.SelectedValue())
                            cmd.Parameters.AddWithValue("@ModuleNo", cboModule.SelectedValue())
                            cmd.Parameters.AddWithValue("@VideoUrl", FilePath)

                            FileUploadVideo.PostedFile.SaveAs(path & FileUploadVideo.FileName)

                            lblError.Text = "File uploaded!"
                            Conn.Close()
                        Catch ex As Exception
                            lblError.Text = "File could not be uploaded; Error: " + ex.message
                        End Try
                    End Using
                Else
                    lblError.Text = "Cannot accept files of this type."
                End If
            End If
        End If
    End Sub

Private Function isValidExtension(fileExt As String) As Boolean

    Dim allowedList As String() = {".mov", ".wmv", ".avi", ".vob", ".mp4"}

    Return allowedList.Contains(fileExt.ToLower)

End Function

推荐答案

尝试调试以下行:

Try debugging the following line:

cmd.Parameters.AddWithValue("@VideoUrl", FilePath)



看看FilePath的价值是什么.

问候,
爱德华



see what''s the value of FilePath.

Regards,
Eduard


这篇关于文件上传路径输入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆