ndraycott 0 Newbie Poster

Hi
I am looking to retrieve and play video files from a database. The url and not the binary data is stored in the database. I previously managed the download file when they were stored in the binary format, but now to increase performance I want to just link to the file stored on the server.
I have some of the code I used before, but want to alter it to get it to find the VideoUrl and not the VideoData or MIME type from the database.

Thanks in advance

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Dim strQuery As String = "select VideoName, VideoUrl from video where UserNo=@UserNo"
        Dim cmd As SqlCommand = New SqlCommand(strQuery)
        cmd.Parameters.Add("@UserNo", SqlDbType.Int).Value = 1

        Dim dt As DataTable = GetData(cmd)
        If dt IsNot Nothing Then
            download(dt)
        End If

    End Sub
    Private Sub getData(ByVal user As String)
        Dim dt As New DataTable()
        Dim connection As New SqlConnection("ConnectionString")
        connection.Open()
        Dim sqlCmd As New SqlCommand("SELECT * from video WHERE UserNo = 1", connection)
        Dim sqlDa As New SqlDataAdapter(sqlCmd)

        sqlCmd.Parameters.AddWithValue("@UserNo", user)
        sqlDa.Fill(dt)
        If dt.Rows.Count > 0 Then

            lblVid1.Text = dt.Rows(0)("VideoName").ToString()

        End If
        connection.Close()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not Page.IsPostBack Then
            GetData(Me.User.Identity.Name)
        End If

    End Sub
    Public Function GetData(ByVal cmd As SqlCommand) As DataTable
        Dim dt As New DataTable
        Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim con As New SqlConnection(strConnString)
        Dim sda As New SqlDataAdapter
        cmd.CommandType = CommandType.Text
        cmd.Connection = con
        Try
            con.Open()
            sda.SelectCommand = cmd
            sda.Fill(dt)
            Return dt
        Catch ex As Exception
            Response.Write(ex.Message)
            Return Nothing
        Finally
            con.Close()
            sda.Dispose()
            con.Dispose()
        End Try
    End Function


    Protected Sub download(ByVal dt As DataTable)
        'Dim url() As Byte = CType(dt.Rows(0)("MIME"), Byte())
        'Response.Buffer = True
        'Response.Charset = ""
        'Response.Cache.SetCacheability(HttpCacheability.NoCache)
        ''Response.ContentType = dt.Rows(0)("MIME").ToString()
        ''Response.AddHeader("content-disposition", "attachment;filename=" & dt.Rows(0)("VideoName").ToString())
        ''Response.BinaryWrite(bytes)
        'Response.Flush()
        'Response.End()
    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.